gpt4 book ai didi

iphone - JSonKit反序列化问题

转载 作者:行者123 更新时间:2023-12-01 19:26:29 26 4
gpt4 key购买 nike

我有JSON作为NSString:

[{"bus_number":"1","created_at":"2011-08-15T23:07:52Z","id":1,"model":"Setra","registar_number":"123456","seats":50,"tour_id":1,"updated_at":"2011-08-15T23:07:52Z"},{"bus_number":"2","created_at":"2011-08-15T23:07:52Z","id":2,"model":"Mercedes","registar_number":"2234","seats":60,"tour_id":1,"updated_at":"2011-08-15T23:07:52Z"}]

并且我正在尝试将此NSString转换为NSDictionary。

当我使用时:
NSDictionary *sourceDictionary = [[response bodyAsString] objectFromJSONString];

我得到这样的NSDictionary:
(
{
"bus_number" = 1;
"created_at" = "2011-08-15T23:07:52Z";
id = 1;
model = Setra;
"registar_number" = 123456;
seats = 50;
"tour_id" = 1;
"updated_at" = "2011-08-15T23:07:52Z";
},
{
"bus_number" = 2;
"created_at" = "2011-08-15T23:07:52Z";
id = 2;
model = Mercedes;
"registar_number" = 2234;
seats = 60;
"tour_id" = 1;
"updated_at" = "2011-08-15T23:07:52Z";
}

)

但是,此NSDictionary存在问题,我无法访问它们的元素,某些元素不是NSStrings(例如模型)。

如何使用NSStrings将JSONString转换为NSDictionary?

编辑:

当我尝试使用以下命令登录控制台时:
for (id key in sourceDictionary) {
NSLog(@"key: %@, value: %@", key, [sourceDictionary objectForKey:key]);
}

我得到异常:
-[__NSArrayM objectForKey:]: unrecognized selector sent to instance 0x1c3a50

最佳答案

这些实际上是NSString,当您将它们打印到控制台时,它们只是没有引号。

关于iphone - JSonKit反序列化问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7218008/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com