I have a php query the returns the following JSON format from a table.
[{"memberid":"18",
"useridFK":"30",
"loginName":"Johnson",
"name":"Frank",
"age":"23",
"place":"School",
},
It needs the following format:
[{"memberid":"18" {
"useridFK":"30",
"loginName":"Johnson",
"name":"Frank",
"age":"23",
"place":"School",}
},
I can figure out where/how to convert this, Where would I create the formatting following:
(1) In the php return?
(2) the JSON instructions for deserialization?
or (3) Some kinb of Obj-C coding instruction?
My end use is a simple Drill Down table using the NSObject, so when I select “memberid” row, I’ll get the child/detail list on the next UITableview.
My Data.plist will look like the following:
Root: Dictionary
V Rows: Array
V Item 0: Dictionary
Title: String 18
V Children Array
V Item 0 Dictionary
Title String 30
etc.
Thanks in advance, this site rocks.
I’m sure its just a typo, but for starters ->
is not valid, there needs to be a comma after the “18”
Anyway, it is easier to fix the php to output the JSON you want than it is to re-organize it in Objective-C. Once you actually have the JSON from the response, you will either need to parse it manually, which isn’t too bad, or use a library (a la http://code.google.com/p/json-framework/ ).
Most communications on the iPhone are done with NSXMLParser or libXML instead of JSON. Both routes are equally hairy as the iPhone deals best with a recursive event-driven XML parser (which most people are unfamiliar with), and does not have native support for JSON (which is by far easier to read).
If JSON isn’t working out for you and you end up moving to XML, look up event-driven parsing, its a bit of work to setup, but very fast once its actually running.