我试图从url获取json,这样返回JSONP响应:
A_string_Blalblalbla(的 JSON_Content )
所以我试图将我的回复序列化,但我得到了:
JSON文本不是以数组或对象开头,而是选项允许未设置片段。
这是我的代码:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
//manager.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];
[manager GET:@"http://miraath.ddns.net:2199/external/rpc.php?callback=jsonp1436888493343&_=1436888517235&m=streaminfo.get&username=miraath1&charset=&mountpoint=&rid=miraath1" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
此外,我尝试将可接受的内容更改为文字:
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
但是我收到了这个错误:
NSLocalizedDescription =请求失败:不可接受的内容类型:text / javascript
所以在这里有任何帮助如何从响应中提取json
答案 0 :(得分:1)
从URI字符串中删除{"type":"result","rid":"miraath1","data":[{"title":"Miraath","song":"\u0642\u0631\u0627\u0621\u0629 \u0641\u062a\u0627\u0648\u0649 \u0641\u064a \u0623\u062d\u0643\u0627\u0645 \u0627\u0644\u0635\u064a\u0627\u0645 - \u0627\u0644\u0634\u064a\u062e \u0645\u062d\u0645\u062f \u0628\u0646 \u0635\u0627\u0644\u062d \u0627\u0644\u0639\u062b\u064a\u0645\u064a\u0646","track":{"artist":"\u0642\u0631\u0627\u0621\u0629 \u0641\u062a\u0627\u0648\u0649 \u0641\u064a \u0623\u062d\u0643\u0627\u0645 \u0627\u0644\u0635\u064a\u0627\u0645","title":"\u0627\u0644\u0634\u064a\u062e \u0645\u062d\u0645\u062f \u0628\u0646 \u0635\u0627\u0644\u062d \u0627\u0644\u0639\u062b\u064a\u0645\u064a\u0646","album":"","royaltytrackid":0,"imageurl":"http:\/\/miraath.ddns.net:2197\/static\/miraath1\/covers\/nocover.png"},"bitrate":"32 Kbps","server":"Online","autodj":"Offline","source":"Yes","offline":false,"summary":"<a href=\"http:\/\/miraath.ddns.net:2199\/tunein\/-stream\/miraath1.pls\">Miraath - \u0642\u0631\u0627\u0621\u0629 \u0641\u062a\u0627\u0648\u0649 \u0641\u064a \u0623\u062d\u0643\u0627\u0645 \u0627\u0644\u0635\u064a\u0627\u0645 - \u0627\u0644\u0634\u064a\u062e \u0645\u062d\u0645\u062f \u0628\u0646 \u0635\u0627\u0644\u062d \u0627\u0644\u0639\u062b\u064a\u0645\u064a\u0646<\/a>","listeners":113,"maxlisteners":1000,"reseller":0,"serverstate":true,"sourcestate":false,"sourceconn":true,"date":"Jul 14, 2015","time":"08:59 PM","rawmeta":"\u0642\u0631\u0627\u0621\u0629 \u0641\u062a\u0627\u0648\u0649 \u0641\u064a \u0623\u062d\u0643\u0627\u0645 \u0627\u0644\u0635\u064a\u0627\u0645 - \u0627\u0644\u0634\u064a\u062e \u0645\u062d\u0645\u062f \u0628\u0646 \u0635\u0627\u0644\u062d \u0627\u0644\u0639\u062b\u064a\u0645\u064a\u0646","mountpoint":"\/stream","tuneinurl":"http:\/\/151.80.100.177:7000\/stream","tuneinformat":"mp3","webplayer":"jplayer","servertype":"IceCast","url":"http:\/\/miraath.ddns.net:2199\/"}]}
变量可以获得干净的JSON响应:http://miraath.ddns.net:2199/external/rpc.php?_=1436888517235&m=streaminfo.get&username=miraath1&charset=&mountpoint=&rid=miraath1
for-in