【问题标题】:NSArray contains a string with missing quotes when converting from JSON? [duplicate]从 JSON 转换时,NSArray 包含一个缺少引号的字符串? [复制]
【发布时间】:2016-05-21 03:56:06
【问题描述】:

我有一个包含以下 JSON 的 NString

str = [{"id":32,
        "date_time":"02-09-2016;23:31:29",
        "message":"tidal wave"},
       {"id":33,
        "date_time":"02-09-2016;23:33:52",
       "message":"mashup"}]

我将其转换为NSArray

jsonObject = [NSJSONSerialization JSONObjectWithData:[str dataUsingEncoding:NSUTF8StringEncoding] options:0 error:&error];

但是,当我NSLog jsonObject 时,我得到以下信息:

jsonObject = (   
        {
        "date_time" = "02-09-2016;23:31:29";
        id = 32;
        message = "tidal wave";
    },
        {
        "date_time" = "02-09-2016;23:33:52";
        id = 33;
        message = mashup;
    }
)

为什么消息中的值tidal wave 有引号,但没有mashup

谢谢。

【问题讨论】:

    标签: ios objective-c json nsarray


    【解决方案1】:

    这就是它的记录方式。键“id”和“message”是字符串。 jsonObjectNSArray< NSDictionary<String, id> *> *,不再与 JSON 相关。

    【讨论】:

    • 谢谢娄。 2个问题。首先,如果 id 和 message 键是字符串,那么 date_time 是什么类型,因为 date_time 在它们周围有引号?其次,我如何能够将 mashup(不确定该对象是什么类型)转换为 NSString?谢谢
    • mashup 可能是一个字符串。你可以po jsonObject[1][@"message"].class
    猜你喜欢
    • 2020-01-03
    • 2021-08-28
    • 2021-08-16
    • 1970-01-01
    • 1970-01-01
    • 2013-07-22
    • 2021-12-27
    • 2012-12-06
    相关资源
    最近更新 更多