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
Post a Comment