2

I have this JSON response string:

{"d":"{\"ID_usuario\":\"000130\",\"Nombre\":null,\"Vipxlo\":0,\"Provmun\":null,\"Descuentos\":null,\"Listaviplocal\":null}"}`

With this code:

- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{
    //Check valid signal

    connection = nil;

    NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
    //data =nil;

    NSArray *jsonArray = [responseString JSONValue];

How can I do it?

1
  • It looks like you did it. What else do you need? Commented Mar 18, 2012 at 21:34

3 Answers 3

10

When you can afford to require iOS 5 you should try NSJSONSerialization.

Your code could look like this but I suggest reading the Docs first.

    NSArray* jsonArray = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:someError]
Sign up to request clarification or add additional context in comments.

1 Comment

NSJsonSerializattion is the best and optimized solution compared to anyother framework.But here i found the pretty good solution for identifying the best among SBJson and NSJSONSerialization (Before the release of ios5.0 SBJSON is the good framework for handling Json objects).
3

This JSON should result in a Dictionary

NSDictionary *jsonDict = [responseString JSONValue];

then use:

[jsonDict objectForKey:@"d"];

4 Comments

Hi I've added NSString *userName = [result objectForKey:@"Nombre"]; but I've got "variable is not a CFString at this time" value for userName. Do you why is it? Thanks for your help.
I'm sorry but, ... I dont have any JSONValue class. Can someone suggest me how to get this class?
@SimoneDemoGentili See cortez' answer. OP uses a third party tool, that isnt needed for iOS 5+.
Where I can find this third party tool?
1

Try using the SBJasonParser library for iOS.

You can then use this code (for all iOS versions):

SBJsonParser* parser = [[[SBJsonParser alloc] init] autorelease];
NSDictionary* myDict = [parser objectWithString: responseString];

Note: Your code above has a JSON Dictionary but you were trying to access it as an Array.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.