0

========== EDIT: ==========

Based on the below question, and below answer to use JSON. I'm rephrasing the question.

How can I take data from boto dynamo and jsonify it?

Right now I have something like this:

adv = #my advertiser
ads = self.swfTable.scan(advertiser__eq = adv)
arr=[]
for a in ads:
    arr.append(a)
str = []
for i in arr:
    str += [json.dumps(fields) for fields in i]
if str is not []:
    json.dumps([ str.to_json() for ad in str ])

How do I turn this into a nice JSON dump or otherwise send it to my php?

========== Original Question: ==========

Forgive me I'm new to PHP.

So I have a stringified array of objects.

Ex: Array [{cat,bat},{mat,hat}] -> ["cat","bat","mat","hat"] (let's call this aList below)

If I know each object pair will have a length of two. Is the only way to reform this Array by parsing the string? Is there any clever PHP way to do this?

I'm trying to move data from python to PHP in this case and sending a printed array seemed like the best / most universal way for me to write the api connection.

Here is my solution in pseudocode:

aList = file_get_contents(myUrl)
splitList = aList.split(",") # is there anyway to exclude "," from being also noticed? ex "app,le","blueberry" should only split 1x?
objects=[]
newObject{}
for int i =0;i<splitList.len; i++
     if i%2
          newObject.append(splitList[i])
          objects.append(newObject)
          newObject = {}
     else:
          newObject.append{list[i]}

Is there are way to do this in fewer lines / more efficiently? Also as mentioned above: is there anyway to exclude "," from being also noticed? ex "app,le","blueberry" should only split 1x?

Tai
  • 1,206
  • 5
  • 23
  • 48

1 Answers1

1

You really should consider cross-language serialization, like JSON or MessagePack. As an example, see docs for PHP's json_decode and Python's json.

Vitaly Chirkov
  • 1,692
  • 3
  • 17
  • 33
  • I tried using jsonify, however it Flask wouldn't allow me to print the JSOn out... hmm maybe I'll try playing with it again. – Tai Aug 11 '14 at 23:09
  • I bet the reason is your sets. Take a look at [this question](http://stackoverflow.com/questions/8230315/python-sets-are-not-json-serializable) – Vitaly Chirkov Aug 11 '14 at 23:11
  • hmm I edited my question, thanks for the response. I'm going to go see if the question you linked to helps. Thanks for helping me find the real issue – Tai Aug 11 '14 at 23:33