【问题标题】:Parse json response in object c from http get request从http get请求解析对象c中的json响应
【发布时间】:2012-10-26 23:35:52
【问题描述】:

我正在尝试解析我从对象 c 中的 http get 请求获得的响应,我已经这样做了:

    NSString *returnValue = [[NSString alloc] initWithData:oRespondeData encoding:NSUTF8StringEncoding];
    SBJsonParser *jParser = [[SBJsonParser alloc] init];
    NSDictionary *JSONresponse = [jParser objectWithString:returnValue];

然后我搜索一个特定的键:

NSArray *jSon1 = [JSONresponse objectForKey:@"links"];

并且在数组中只有一个元素,如果我记录它,我有这个:

NSLog(@"%@",[jSon1 objectAtIndex:0]);

日志:

(
"Video.720p.X264-..",
"",
"http://video/dl/Video.720p.X264-.."
)

如何使用 http 获取 url?我已经尝试了一切,我也尝试修剪字符串以删除空格,但似乎它不是 nsstring,因为我收到了

[__NSArrayM stringByTrimmingCharactersInSet:]: unrecognized selector sent to instance

我该怎么办?

【问题讨论】:

  • 您支持哪些版本的 iOS?
  • 我是在 Mac OS X 上做的,不是 iphone...

标签: objective-c json cocoa http nsstring


【解决方案1】:

[jSon1 objectAtIndex:0]

返回一个由 3 个单独字符串组成的数组,所以如果你想获取第三个字符串,你可以这样做:

NSArray *links = [jSon1 objectAtIndex:0];

NSString *httpUrl = [links objectAtindex:2];

希望我能正确理解您的问题。

【讨论】:

    猜你喜欢
    • 2017-12-04
    • 1970-01-01
    • 2016-04-14
    • 2013-11-23
    • 1970-01-01
    • 2014-09-01
    • 1970-01-01
    • 2021-08-28
    • 1970-01-01
    相关资源
    最近更新 更多