php - Extracting values from JSON iOS -


I am developing an app that communicates with my own server (Apache-> PHP) and I have a simple The JSON dictionary is sending the PHP code for the app from the server:

  $ aJSON = array ('result' = & gt; true, 'Result_Msg' = & gt; "success !!!" ); Echo json_encode ($ aJSON);  

I want to extract values ​​from the keys with these lines of code: 'Result' and 'Result_Msg':

  // Receive logging and converted JSON / NSMutableDictionary NsLog (@ "rectangle =% @", DJSON); BOOL B = [DJSN ObjectForcae: @ "Response"]; NSString * string = [DJSON ObjectForcae: @ "Result_Msg"]; NSLog (@ "% @", [DJSON ObjectForcae: @ "Respapsation"]); NSLog (@ "% @", [DJSON Manfurky: @ "Response Mags"]); NSLog (@ "% @", [DJSON Manfurky: @ "Response"]); NSLog (@ "% @", [DJSON ObjectForcae: @ "Response"]);  

And my printed / logged in JSON result looks like this:

responseDict = {result = 1; "Result_Msg" = "User successfully added. Please verify your mail address."; }

Unfortunately every NSLog as well as variable "B" and "string" are equal (zero).

Apart from this, I'm confused about a little bit like the results without the key quotation (""), but Result_Msg is in quote.

Hope someone can help. thank you in advanced!

Edit:

The variable "DJSON" is already an NSDictionary (/ MutableDic) I am doing this with these lines:

  NSError * errorJson = Zero; NSMutableDictionary * dJSON = [NSJSONR rialization JSONObjectWithData: _responseData option: kNilOptions error: & amp; ErrorJson]; If (error) {UIAlertView * Warning .... Return; }  

// --- Analyze and extract values ​​--- //

There are two easy ways to withdraw a dictionary from your PHP code.

The first, where you do not need to change your call in your server in your call - c is to use this function:

  - (NSDictionary *) Dictionary framesAndata: (NSDTA *) data {NSError * error; NSDictionary * dictionaryParsed = [NSJSONSerialization JSONObjectWithData: Data Option: 0 Error: & amp; Error]; If (parsed! Dictionary) {if (error) {NSLog (@ "error parsing dictionary"); } Return zero; } Return dictionary was parsed; }  

Second, use the library, however, provide many useful things.

Edit

Then, you can get a Blean in this way:

< Pre> BOOL myBool = [[myDictionary valueForKey: @ "mike"] boolValue];

and with your string:

  NSString * myString = [myDictionary objectForKey: @ "mike"];  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -