python - urlencode of json data -


originating different question of mine, trying find elegant solution in python code (mongo php turns array strings)

i have valid json file, array of elements - "" (not single ')

the following python code creates post request causes php json_decode fail $_post array looks so:

[{u'amount': u'1 (14 ounce) can', u'name': u'black beans, drained', u'short_name': u'black beans'}, {u'amount': u'1 (8 ounce) jar', u'name': u'salsa', u'short_name': u'salsa'}] 

(with u'' in strings)

the code created this:

json_data = open(json_filename) elems = json.load(json_data) running_index=0 elem in elems:     data = urlencode(elem)     result = urllib2.urlopen(base_url,data) 

any elegant way make data "php ready"?
elegant == other doing (which horrificly works):

data = data.replace("u%27","%22") data = data.replace("%27","%22") 


Comments

Popular posts from this blog

What can cause "Required Package 'IndyCore' not found" when compiling a Delphi 2010 project? -

Change the color of an oval at click in Java AWT -