JSONKit(在 RestKit 中)将 JSON 转换为 NSArray
我使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
json-framework 是可用于解析 JSON 的众多第三方库之一。
json-framework is one of many third-party libraries you can use to parse JSON.