0

我有一个包含字符串的数组,而 json 有对象,我只需要从数组中获取 json。如何从数组中获取json?我在下面显示了数组:

array (
    "",
    "",
    "",
    "sda@sdas.com",
    "[{  \"field_value\" : \"\\/Users\\/poornima\\/Library\\/Application Support\\/iPhone Simulator\\/5.1\\/Applications\\/BCA9D949-D85D-4CA7-B753-7315C0383137\\/Documents\\/EGOoTtqT4e.png\",  \"field_name\" : \"Photo\"},{  \"field_value\" : \"\",  \"field_name\" : \"Signature\"},{  \"field_value\" : \"\",  \"field_name\" : \"File Upload\"}]",
    "",
    "",
    "",
    "37.785834",
    "-122.406417",
    "2013-02-01 05:44:01",
    "superadmin@gmail.com",
    ""
)

任何帮助,将不胜感激

4

2 回答 2

0

你所要做的 :

for(NSString *string in arrayName) {
NSDictionary *dicReturn = [string JSONValue]; if(dicReturn !=nil){ NSString * fieldvalue =[dicReturn objectForKey:@"field_value"]; NSString *fileName =[dicReturn objectForKey:@"field_name"]; } }

于 2013-02-01T12:49:47.883 回答
0

看起来像这样..

NSString *jsonString = @"your json";
NSData *JSONdata = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSError *jsonError = nil;
if (JSONdata != nil) {
    //this you need to know json root is NSDictionary or NSArray , you smaple is NSDictionary
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:JSONdata options:0 error:&jsonError];
    if (jsonError == nil) {
        //every need check value is null or not , json null like ( "count": null )
        if (dic == (NSDictionary *)[NSNull null]) {
            return nil;
        }

        //every property you must know , what type is

        if ([dic objectForKey:@"count"] != [NSNull null]) {
            [self setCount:[[dic objectForKey:@"count"] integerValue]];
        }
        if ([dic objectForKey:@"item"] != [NSNull null]) {
            NSArray *itemArray = [dic objectForKey:@"item"]; // check null if need
            for (NSDictionary *itemDic in itemArray){
                NSString *_id = [dic objectForKey:@"id"]; // check null if need
                NSNumber *found = (NSNumber *)[dic objectForKey:@"found"];
                //.....
                //.... just Dictionary get key value
            }

        }
    }
}
于 2013-02-01T12:34:06.883 回答