【发布时间】:2013-02-25 12:52:09
【问题描述】:
我正在尝试解析一些 JSON。为简单起见,我将使用 github 上的默认示例进行解释: 运行时:
NSURL *url = [NSURL URLWithString:@"http://httpbin.org/ip"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation
JSONRequestOperationWithRequest:request success:^(
NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSLog(@"IP Address: %@", [JSON valueForKeyPath:@"origin"]);
} failure:nil];
[operation start];
我得到了正确的输出记录。但是,当我将示例的内容(基本上是 1 个元素)复制到 txt 或 html 文件(因此 URLWithString 获取 @"http://my server address/file.txt")时,将其放在我的测试服务器上并尝试从那里赞美,我没有输出。这有什么问题?感谢您的宝贵时间!
(注意:如果我访问 http:// 我的服务器地址 /file.txt 我可以清楚地看到那里的内容,所以这不是问题)
编辑:按照建议,内容是: "{ “起源”:“10.44.119.100” }"
【问题讨论】:
-
您应该将您复制的确切内容添加到您的问题中,以便人们可以看到它的样子。
-
感谢 Firoze!尽管可以在 URLWithString 中找到它,但在那里看到它会更好。
标签: objective-c json parsing afnetworking