gpt4 book ai didi

html - 如何从 iOS 中的文件中解析 JSON?

转载 作者:IT老高 更新时间:2023-10-28 12:46:31 30 4
gpt4 key购买 nike

我正在尝试解析 JSON 文件中的数据。我正在尝试将解析/获取的数据放入带有标签的 UIView 或 webview 中。JSON 文件如下所示:

{"bodytext": "<p>\n Some lines here about some webpage (&ldquo; <em>Site</>&rdquo;) some more lines here. \n </p>\n\n <p>\n some more stuff here </p>
}

这里有关于 Stack Overflow 的帖子,展示了如何解析从 Web URL 检索到的 JSON,但实际上我已经有了一个想要解析的 JSON 文件。如何从文件中解析 JSON?

最佳答案

  1. 创建空文本文件(新文件/其他/空),例如“example.json”

  2. 将json字符串粘贴到文件中。

  3. 使用这些行获取数据:

    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"example" ofType:@"json"];
    NSData *data = [NSData dataWithContentsOfFile:filePath];
    NSArray *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];

关于html - 如何从 iOS 中的文件中解析 JSON?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18520949/

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