gpt4 book ai didi

ios - 从 JSON 获取字典

转载 作者:行者123 更新时间:2023-11-28 20:14:21 25 4
gpt4 key购买 nike

我正在尝试从 json 中获取字典,但以下代码似乎有效。我正在获取 JSON,但无法从中获取字典。

NSString *str = [[NSMutableString alloc] initWithData:responseCust encoding:NSUTF8StringEncoding];
NSLog(@"CUSTOMER string -----################ %@", str);

if(str.length>5)
{
SBJSON *jsonparser=[[SBJSON alloc]init];
NSDictionary *res= [jsonparser objectWithString:str];

NSLog(@"Contants Results %@",res);

[jsonparser release];
[str release];
}

谢谢。

最佳答案

请按照下面的代码

NSURL * url=[NSURL URLWithString:str];

NSData * data=[NSData dataWithContentsOfURL:url];

NSError * error;

//Get json data in Dictionary
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingMutableContainers error: &error];

NSLog(@"%@",json);

试试这个..

关于ios - 从 JSON 获取字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18636113/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com