tags:

views:

73

answers:

1

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.

+1  A: 

I'm sure its just a typo, but for starters ->

 [{"memberid":"18" {
                    "useridFK":"30",
                    "loginName":"Johnson",
                    "name":"Frank",
                    "age":"23",
                    "place":"School",}
                    },

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.

G. Shearer
The rest of my app does the deserialization fine, But it think that if I get the incoming JSON in the right format, it will convert to the array format correctly, Do you know what format the above is called? It would help on my quest. Michael
Michael Robinson
we're going to use php
Michael Robinson
Were going to use php, thanks
Michael Robinson
I would call it JSON-within-JSON, not really sure if there is a technical title for it as it is somewhat expected to use JSON objects which contain more JSON objects, its just a tree-structure the same as XML/HTML
G. Shearer