क्या आप सिस्टम कॉल कर सकते हैं? आप इस प्रकार का अजगर स्क्रिप्ट का उपयोग कर सकता है json में अचार डेटा कन्वर्ट करने के लिए:
<?php
exec("python pickle2json.py -p pickled_data.txt", $json_data = array());
?>
या यदि:
# pickle2json.py
import sys, optparse, cPickle, os
try:
import json
except:
import simplejson as json
# Setup the arguments this script can accept from the command line
parser = optparse.OptionParser()
parser.add_option('-p','--pickled_data_path',dest="pickled_data_path",type="string",help="Path to the file containing pickled data.")
parser.add_option('-j','--json_data_path',dest="json_data_path",type="string",help="Path to where the json data should be saved.")
opts,args=parser.parse_args()
# Load in the pickled data from either a file or the standard input stream
if opts.pickled_data_path:
unpickled_data = cPickle.loads(open(opts.pickled_data_path).read())
else:
unpickled_data = cPickle.loads(sys.stdin.read())
# Output the json version of the data either to another file or to the standard output
if opts.json_data_path:
open(opts.json_data_path, 'w').write(json.dumps(unpickled_data))
else:
print json.dumps(unpickled_data)
इस तरह, यदि आपके एक फ़ाइल से डेटा हो रही आप कुछ इस तरह कर सकता है आप किसी फ़ाइल को यह करने के लिए इसे बाहर सहेजना चाहते:
<?php
system("python pickle2json.py -p pickled_data.txt -j p_to_j.json");
?>
सभी संभावित रूप से ऊपर कोड सही नहीं (मैं एक PHP डेवलपर नहीं कर रहा हूँ) है, लेकिन आप के लिए यह काम की तरह कुछ होता?
स्रोत
2010-06-14 21:56:11
आपने बताया कि क्रमबद्धरण आपके नियंत्रण में नहीं है। आप इस मसालेदार डेटा को कैसे प्राप्त कर रहे हैं? एक स्थानीय फाइल? –
यह Django में डेटाबेस से आता है, यह django सत्र तालिका में session_data है। मैं शायद सत्र_डेटा को जेएसओएन के रूप में क्रमबद्ध करने के लिए सत्र मिडलवेयर लिख रहा हूं। मैं बस कामना करता हूं कि मुझे इसके लिए Django ऐप को संशोधित करने की आवश्यकता नहीं है। – Ciantic