如何将Json字符串转换为NSArray? [英] How to convert a Json String into a NSArray?

查看:161
本文介绍了如何将Json字符串转换为NSArray?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试将某些对象的JSON表示转换为 NSArray
我使用 RestKit 通过我们的API获取响应,现在我想将 RKResponse 转换为对象数组。我该怎么做?

I am currently trying to convert the JSON Representation of some Objects into an NSArray. I used RestKit to get the Response through our API and now I want to convert the RKResponse into an Array of Objects. How can I do this ?

推荐答案

 NSData* data = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSArray *values = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];  // if you are expecting  the JSON string to be in form of array else use NSDictionary instead

以上代码适用于iOS 5及以上版本

The above code works good for iOS 5 and above

这篇关于如何将Json字符串转换为NSArray?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆