gpt4 book ai didi

iphone - 如何在 iPad 应用程序中解析 JSON 字符串?

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

我想转换我数据库中的图像以在我的 iAd 应用程序中检索它,为此我使用了 JSON,但我没有正确完成它。

在我的 onTouch 按钮里面我写了这段代码

//create string contain url address for php file, the file name is phpFile.php,it receives parameter :name 
NSString *strURL=[NSString stringWithFormat:@"....my.php","hhhhh"];

//to execute php code
NSData *dataURL=[NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];

//to receive the returned Result
NSString *strResult = [[[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding]self];
NSLog(@"%@",strResult);

最佳答案

有不同的方法可以做到这一点:

  1. 如果您的部署目标是 iOS 5.0 及更高版本,您可以使用:NSJSonSerialization
  2. 如果你想支持 5.0 以下的版本,你可以使用许多库之一来实现,我个人认为 SBJson很好。看看这个片段来获得一个想法:

    NSString *dataString = [[NSString alloc] initWithData:self.receivedData encoding:NSUTF8StringEncoding];
    NSDictionary *dic = [dataString JSONValue];
    NSArray * element = [dic objectForKey:@"jsonKey"];
    NSString * someSimpleElement = [dic objectForKey:@"jsonKey"];

关于iphone - 如何在 iPad 应用程序中解析 JSON 字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8847972/

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