开发者

Obtaining right value from "JSON-style" NSString in objective-c

I am trying to get the NSString "Bonjour" from the JSON-style NSString below:

[[["Bonjour","Hello","",""]],,"en",,[["Bonjour",[4],1,0,1000,0,1,0]],[["Hello",4,[["Bonjour",1000,1,0]],[[0,5]],"Hello"]],,,,2]

Implementing the following code gives me null, assuming result is the NSStr开发者_JAVA技巧ing above

NSDictionary *td = [result JSONValue];
NSLog(@"\n%@", td);  

How can I grab "Bonjour" from this JSON-style string?


I don't think this is well-formed JSON. For one thing this would return an array.. (surrounded by [], not {}). Also, your arrays have empty entries (',' with nothing separating them)

Are you using SBJSON?

If you consult NSObject+JSON.h you'll see this comment:

/// Returns the NSDictionary or NSArray represented by the receiver's JSON representation, or nil on error

There has been an error. Check your console output, you should see an error posted there.


I'm somewhat unsure how the array you posted is a JSON-style NSString, but I believe the NSDictionary you get back should basically store key value pairs exactly as they appeared in the JSON original. For example, if you had JSON like:

{key: "value"}

Then you'd get an NSDictionary with a "key" key matched to a value of "value".

Perhaps the reason your NSDictionary is null is because you aren't passing it something that JSONValue understands?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜