JSONKit(在 RestKit 中)将 JSON 转换为 NSArray

发布于 2024-11-30 23:07:21 字数 729 浏览 1 评论 0原文

我使用 RestKit 进行 HTTP 请求,并且通过一些请求,我得到一些总线的 JSON 响应:

[{"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"}]

我将其放入方法中:

- (void)request:(RKRequest*)request didLoadResponse:(RKResponse*)response {  
    NSLog(@"%@", [response bodyAsString]);
}

因为,我在这个 JSON 中有多个总线,我如何轻松解析/解码或执行任何操作将其转换为 NSArray 或其他内容以便轻松访问元素?

编辑:我需要如何使用 JSONKit 执行此操作的代码示例,该示例已在 RESTKit 中实现。

I'm using RestKit for HTTP requests, and with some request, I get JSON response with some busses:

[{"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"}]

I'm getting it into method:

- (void)request:(RKRequest*)request didLoadResponse:(RKResponse*)response {  
    NSLog(@"%@", [response bodyAsString]);
}

Becouse, I have multiple busses in this JSON, how can I easily parse/decode or whathever do to convert this into NSArray or something for easily accesing into elements?

EDIT: I need code sample how to do this with JSONKit, who is already implemented in RESTKit.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

压抑⊿情绪 2024-12-07 23:07:21

json-framework 是可用于解析 JSON 的众多第三方库之一。

json-framework is one of many third-party libraries you can use to parse JSON.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文