1

我正在尝试使用来自服务器的 jsonkit 或 nsjsonserialization 解码 json 字符串,但我得到冒号:标记更改为等号和逗号,更改为分号;例如来自服务器:

"response": { "status": "OK","message": "","timestamp": "30 Mar 2013 11:33:08", 
"url":"/abc/api/getconfig/dev-game?language=en" }...

但我得到的回应是:

JSONDecoder *decodedData = [[JSONDecoder alloc] initWithParseOptions:JKParseOptionStrict];
NSDictionary *parsedList = [decodedData objectWithData:responseData];

或者:

NSError *jsonError = nil;
NSDictionary *parsedList = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&jsonError];

给我:

response =     {
    message = "";
    status = OK;
    timestamp = "30 Mar 2013 11:33:08";
    url = "/abc/api/getconfig/dev-game?language=en";
};
result =     {
    meta =         {
        dateLastModified = "29 Mar 2013 11:59:17";
    };

这在尝试解析时给我带来了很多问题。我可以:

NSSTring *jsonString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

或者将请求 url 放在浏览器或 jsonlint.com 中,我得到正确的格式,但我需要在字典中,因为我需要能够解析它。除非将其放入不同的数据类型会更好,因为我将尝试找到特定的键,即如果我有 column_1、column_2 则获取每个“列”...提前致谢。

4

1 回答 1

1

JSONKit and NSJSONSerialization will parse the JSON string for you and create the NSDictionary/NSArray/NSString/NSNumber objects for you. You don't have to parse anything yourself. You're seeing equal signs and such because you're printing a description of the parsed response object (probably using NSLog).

于 2013-03-30T05:24:03.813 回答