Value of a JSON or NSDictionary to integer

0

I'm doing tests on a webservice by taking the value of a JSON that returns (it's an integer) it throws me an error.

To take the value I do it with:

[[respuesta valueForKey:@"code"] integerValue]

The error you're leaving is a:

  

[__ NSSingleObjectArrayI integerValue]: unrecognized selector sent to instance 0x618000016830

If I make a NSLog of [respuesta valueForKey:@"code"] as NSString I get the number but separated in parentheses and spaces, something like this: ( 1 ) . The 1 would be the value I want to pass to the whole.

    
asked by Popularfan 20.12.2016 в 22:04
source

2 answers

0

After doing several tests I have solved it, I leave the solution in case someone happens the same thing some time.

The web returned the JSON between brackets [] and inside the braces {} so this objective-C sees it as an array with index 0 where to access it well had to do it this way: [[[answer objectAtIndex : 0] valueForKey: @ "code"] integerValue]

The way I tried it at the beginning served only if the code was between braces {}

    
answered by 21.12.2016 / 09:57
source
1

You can try to Parse the objects with CocoaPods

link

    
answered by 12.01.2017 в 14:10