我们如何在 NSstring ios 中存储一堆 json 键值

How can we store bunch of json key values in NSstring ios

  source =   {
            Address1 = "3244 W WASHINGTON ST , ";
            Address2 = "";
            City = "ANDERSON     ";
            Name = "<null>";
            PhoneNo = "<null>";
            ProviderId = "<null>";
            ProviderName = "<null>";
            State = IN;
            Zip = "46011-";
        };

嗨,我是 ios 的新手,我正在将我的应用程序与服务集成,在收到服务的响应后,我存储了上面的字典值,如下面的代码,但它显示异常

请帮助我如何在一个 NSstring 中存储上述 kay 值

我的代码:-

 NSString *SourceAdrees = [NSString stringWithFormat:@"%@\n %@ %@ %@" ,[[[[[dicCurrentIndex valueForKeyPath:@"source"]valueForKey:@"Address1"]valueForKey:@"City"]valueForKey:@"State"]valueForKey:@"Zip"]];

   NSLog(@"SourceAdrees is %@",SourceAdrees);

如果你想在一个字符串中显示值,那么有一种方法叫做

stringByAppending

使用那个,即

NSString *SourceAdrees=[SourceAdrees stringByAppendingString:[dicCurrentIndex valueForKey: @"Address1"]stringByAppendingString:[dicCurrentIndex valueForKey:@"City"]]];

如果我理解你想要做什么,代码将如下所示:

NSDictionary *sourceDict = dicCurrentIndex[@"source"];
NSString *sourceAddress = [NSString stringWithFormat:@"%@\n %@ %@ %@", 
  sourceDict[@"Address1"], 
  sourceDict[@"City"], 
  sourceDict[@"State"], 
  sourceDict[@"Zip"] ];

(变量名要以小写字母开头,单词是"address",不是"SourceAdrees")