gpt4 book ai didi

objective-c - 解析 json 提要到 iphone

转载 作者:搜寻专家 更新时间:2023-10-30 19:56:55 25 4
gpt4 key购买 nike

我试图将公共(public) json flickr 提要解析到 iphone 中。我遇到了错误..

-JSONValue failed. Error trace is: (
"Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Unrecognised leading character\" UserInfo=0x4b43100 {NSLocalizedDescription=Unrecognised leading character}"
).....

下面是 json 提要:

http://api.flickr.com/services/feeds/photos_public.gne?tags=hackdayindia&lang=en-us&format=json .....

如果你们能帮助我,我将非常感激enter image description here

最佳答案

由于 Flickr API 返回的 jsonFlickrFeed() 回调,您的响应数据不是有效的 JSON。为了获得有效的 JSON,请将 nojsoncallback=1 添加到您的查询中。使用您的示例,相应的 URL 是:

http://api.flickr.com/services/feeds/photos_public.gne?tags=hackdayindia&lang=en-us&format=json&nojsoncallback=1

如果您在 http://jsonlint.com 中使用上述 URL 的响应,它会告诉您它是有效的 JSON。

nojsoncallback 记录在 http://www.flickr.com/services/api/response.json.html


如何阅读该响应的快速示例。 JSON 字符串的顶级元素是一个对象,它通常被 JSON 解析器映射到一个字典:

// Obtain the JSON string from Flickr API
NSString *jsonString = …;

// Parse the JSON string into a dictionary
// (in this example, via SBJSON)
NSDictionary *responseObject = [jsonString JSONValue];

// The dictionary has an entry called "items", which is an array
NSArray *items = [responseObject objectForKey:@"items"];

// Iterate over the items. Each item is an object, hence a dictionary
for (NSDictionary *item in items) {
// Each item dictionary has an entry called "author_id", which is a string
NSString *authorId = [item objectForKey:@"author_id"];

// Log the author id
NSLog(@"author_id = %@", authorId);
}

关于objective-c - 解析 json 提要到 iphone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5563828/

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