更新时间:2022-12-11 11:08:03
首先,我建议将数据格式更改为以下形式:
First of all I'd suggest changing the format of your data to something like this:
{
"london":{
"link":"http://www.London.co.uk",
"moredata":"..."
},
"paris":{
"link":"http://www.Paris.fr",
"moredata":"..."
}
}
这将代表具有相关属性的城市.在您的版本中,无法找到特定城市的正确链接.
This will represent a city with it's associated properties. In your version it's impossible to lookup the right link for a specific city.
然后,您可以按以下方式解析和访问不同的部分:
Then you can parse and access the different parts as follows:
NSString *json = @"{\"london\":{\"link\":\"http://www.London.co.uk\",\"moredata\":\"...\"},\"paris\":{\"link\":\"http://www.Paris.fr\",\"moredata\":\"...\"}}";
NSData *data = [json dataUsingEncoding:NSUTF8StringEncoding];
NSError *error;
NSDictionary *cities = [NSJSONSerialization JSONObjectWithData:data options:nil error:&error];
NSLog(@"link to london: %@", cities[@"london"][@"link"]);
>> link to london: http://www.London.co.uk
此后,您必须使用提取的链接来填充Web视图.
After this You have to feed your webview with the extracted link.