objective c - Parse JSON without top-level label -


I am working with the DJENGO-PISTON and JSN is in production purpose, but there is some problem because the output is not There are no top-level labels for each example For each example I've read data in a dictionary, then created an array based on Objectwork: @ "Foo" But in my case, I have the top-level text based on No basis. JSON has been generated by the piston:

  [{"text": "pain intensity", "question_number": 1, "id": 1}, { "Text": "personal care (washing, dressing, etc.)", "question_number": 2, "id": 2}, {"text": "weightlifting", "question_number": 3, "id": 3} , "Id": 5, "id": 5}     east> 

]

What do I want to do, an ID Ends with an array containing objects with text and question numbers.

Any advice?

The NSJSONSerialization class is created in the right way:

  NSArray * parsedJSON = [JSONObjectWithData: myData options: myOptions error: & amp; Error];   

Whenever a MyData object (a NSDT instance) includes a valid JSON string using a supported JSON encoding, and that top-level element of that JSN string is an array it is your In the example.

When you do this with your example JSON string, you should get an NSArray with 5 dictionaries. You can do something like this:

  NSMutableArray * newArray = [[NSMutableArray alloc] init]; For (Int i = 0; I & lt; [ParsedJSON count]; I ++) {Myclass * New object = [[Mackle Elok] Init]; NSDictionary * QuestionPop = [PassageJason ObjectOutIndexX: i]; [MyObject setText: [question objection objectForKey: @ "text"]]; [MyObject setQuestionNumber: [Query Object object: @ "Question_Number"]]; [MyObject setID: [Query object object: @ "id"]]; [NewerAudObject: new object]; }   

The above is assumed that you have defined a class called MyClass with the properties named text, question number and ID.

Comments