objective-c - 将JSON对象导入NSArray

标签 objective-c ios json nsarray

尝试在Objective-C中解析此JSON对象,并使用这些对象创建NSArray。
第一个值是一个计数器,并且特定于该对象。所有其他值都是唯一的。

{ "myData": [
["1","1","110","dollar","8.0","2.8","0.1","11.6"],
["2","1","110","euro","4.0","3.2","1.5","4.4"],
["3","1","120","rupier","6.0","2.9","1.3","10.8"],
["4","1","120","dinero","4.0","3.3","1.5","4.4"],
["5","2","130","drahmer","8.0","2.9","1.3","11.2"],
] }

试过这段代码:
 NSDictionary* json = [NSJSONSerialization 
                          JSONObjectWithData:myData
                          options:kNilOptions 
                          error:&error];

    NSArray *currencyInformation = [json objectForKey:@"myData"];

但是物体不在那里。虽然数组的数量为5。

最佳答案

数组中的每个对象都是数组本身,因此:

NSDictionary* json = [NSJSONSerialization 
                      JSONObjectWithData:myData
                      options:kNilOptions 
                      error:&error];

NSArray *currencyInformation = [json objectForKey:@"myData"];

for (NSArray *info in currencyInformation) {
    // Then access each "column" with [info objectAtIndex:0,1,2,3,...]
}

关于objective-c - 将JSON对象导入NSArray,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9762223/

相关文章:

objective-c - 缩放预览: use NSTextView, NSTextField、CATextLayer 或drawInRect?

ios - touches在约束范围内移动?

java - 我怎么能把json解析成java

objective-c - 告诉自定义委托(delegate)何时调用方法

ios - 如何在不使用 sender.tag 方法的情况下管理 UItableViewCell 中的 UIbutton?

objective-c - Swift Extension 无法向 Objective-C 类添加重载方法

iphone - 在 iPhone 应用程序中发送/存储凭据

ios - 有没有办法在后台让我的应用程序在 CMMotionActivity 更改时收到通知?

json - 如果有 1 个元素,如何防止 ConvertFrom-Json 折叠嵌套数组

javascript - 在 jQuery 的匿名函数中将 HTML5 数据写入 JSON