【问题标题】:How to convert the json string into array of elements?如何将json字符串转换为元素数组?
【发布时间】:2012-05-23 11:42:33
【问题描述】:

这是我获取 json 响应字符串的代码

我通过这个方法得到这个字符串

NSDictionary *selector = [json valueForKey: @"Title"];
NSMutableArray *dictArray = [[NSMutableArray alloc] initWithObjects: selector,nil];
str1=[[dictArray objectAtIndex:i] valueForKey:@"CompanyName"];

打印“str1”

我来了

(
    "hello@developer.com"
),
    (
    "hello@developer.com",
    "helloworld@microsoft.com"
),
    (
    "hello@developer.com"
),
    (
    "hello@developer.com"
),
    (
    "hello@developer.com"
),
    (
    "hello@developer.com"
),
    (
    "hello@developer.com"
),
    (
    "hello@developer.com"
)

)

我正在尝试使用“,”运算符存储在数组中

喜欢这样

NSArray *SplitStringArray = [str1 componentsSeparatedByString:@", "];

但我没有将字符串拆分为元素数组

谁能帮帮我?

【问题讨论】:

标签: ios xcode json nsmutablearray nsdictionary


【解决方案1】:
    NSDictionary *selector = [json valueForKey: @"Title"];

    NSMutableArray *dictArray = [[NSMutableArray alloc] initWithObjects: selector,nil];

    NSMutableArray *str1Array=[[dictArray objectAtIndex:i] valueForKey:@"CompanyName"];


        //note this line
    NSMutableArray *SplitStringArray =[[NSMutableArray alloc]init];

    for (id eachArray in str1Array) {


        if ([eachArray count]>0) {


            for (int i = 0; i<[eachArray count]; i++) {

                NSString *emailid=[NSString stringWithFormat:@"%@",[eachArray objectAtIndex:i]];

                [SplitStringArray addObject:emailid];


            }

        }

    }

    NSLog(@"SplitStringArray : %@",SplitStringArray);

【讨论】:

  • 更新代码并注意 NSMutableArray *SplitStringArray =[[NSMutableArray alloc]init];
  • 之前我初始化了数组]
  • 感谢老兄,并有一个很好的学习实践...快速参考加入这里chat.stackoverflow.com/rooms/682/iphone-ipad
  • 嗨朋友,我得到了上述解决方案,但我没有得到解决方案
  • 嗨朋友,我得到了上述解决方案,但我没有得到解决方案 { Description = "Mic";EndDate = "/Date(1275832800000+0000)/";FriendlyName = TB3259;Id = 4;位置=“N-4105 楼”;演讲者=({公司=惠普;电子邮件=“janedoe@hp.com”;姓名=“Jane Doe”;职务=“副总裁”;});开始日期=“/日期(1275829200000+0000)/"; },这是我的 json 响应,因为我得到了选择器数据,但是每当我尝试获取友好名称时,我没有得到那个。在 str1array 中,每当我附加表格单元格时,都会获取值。执行退出。我会做什么请帮帮我
【解决方案2】:
NSMutableArray *SplitStringArray = [[NSMutableArray alloc]init]; 
[SplitStringArray setArray:[str1 componentsSeparatedByString:@","]];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-07
    • 1970-01-01
    • 2015-08-02
    • 1970-01-01
    • 2017-07-20
    • 2015-04-05
    相关资源
    最近更新 更多