从Web服务获取多个值

时间:2013-11-25 07:19:37

标签: ios nsstring

我有一个web服务,其中参数“upload_images”具有多个值。我怎样才能获得这些价值观。我正在使用SBJson。这是我的回复

{
    "node_title": "thk",
    "category": "Boating",
    "description": "Fg",
    "link": "",
    "nid": "446",
    "post date": "Mon, 11/25/2013 - 07:04",
    "upload_images": "http://prod.kyzook.com/?q=sites/prod.kyzook.com/files/styles/medium/public/2013-11-25%2007%3A03%3A25%20%2B0000.png&itok=WIBTqzbC, http://prod.kyzook.com/?q=sites/prod.kyzook.com/files/styles/medium/public/2013-11-25%2007%3A03%3A58%20%2B0000.png&itok=AhoLUnou"
 }

2 个答案:

答案 0 :(得分:1)

如果我正确理解您的问题,upload_images包含一串逗号分隔的网址,您想要提取它们。

您可以使用NSString的方法componentsSeparatedByString轻松实现此目的,例如

NSString *uploadImages = response[@"upload_images"];
NSArray *imageURLs = [uploadImages componentsSeparatedByString:@", "];

我假设response是一个持有解析后的响应的NSDictionary对象。

答案 1 :(得分:0)

您可以将"upload_images"作为string获取,并使用array方法转换为componentsSeparatedByString:

NSString *uploadImages = [response objectForKey:@"upload_images"];
NSArray *imageUrlArray = [uploadImages componentsSeparatedByString:@", "];