I have a problem with JSON parsing. When I hit the URL, I get this type of JSON response:
// JSON 1 {"data": {"array": ["3", {"array": [ "ID": "1", "Message": "Hello", "Sender": "Inot"}, {"id": "2", "Message": "World", "Sender": "Inot"} "MSG0001: Success", "status": "OK"} <"id": "," "message": "hello", "sender": "marza"}]}]}, "message" / code> But if the result of the data is just 1, then the JSON response is like this:
// JSON 2 {"data": {"array": "" " MSG0001: Success ":" "" {"ID": "3", "Message": "Hello", "From": "Margin I apply this code to get the ID, message, and sender value, and JSON 1: "message" "status": "OK"}
But work fine on JSON 2. I have JSON-framework. And the question is how to find out that JSON is the response object ({}) or array ([]) ??
// String Parser in JSON NSDictionary * json = [myString JSONValue]; // Get all objects NSArray * items = [json valueForKeyPath: @ "data.array"]; NSArray * array1 = [[Objects ObjectInxt: 1] ObjectForreqi: @ "Array"]; NSEnumerator * enumerator = [array1 objectEnumerator]; NSDictionary * items; Whereas (object = (NSDictionary *) [counterconducting next object]) {NSLog (@ "id =% @", [object objectForKey: @ "id"]); NSLog (@ "Message =% @", [Item ObjectForcae: @ "Message"]); NSLog (@ "Sender =% @", [Object ObjectForcae: @ "Sender"]); }
You can use id and the object You can check that you get NSARA or NSDRIATION in this way:
id object = [jsn value forekepath: @ "data. Hey"]; {// item is a dictionary} {// item is a dictionary}} {// item is an array} and if ([object iskindoffs: [nsata class]]) {// item is a dictionary} < / Div>
Comments
Post a Comment