我正在创建一个简单的登录页面。在我的项目中,我想解析json字符串。但它给了我跟随的错误。
-JSONValue failed. Error trace is: (
"Error Domain=org.brautaset.JSON.ErrorDomain Code=4
\"Valid fragment, but not JSON\"
UserInfo=0xa6e70a0 {NSLocalizedDescription=Valid fragment, but not JSON}"在我的代码中,如果我要放另一个json字符串而不是它正在工作的话。另外,我最初的json字符串也给了我浏览器中的数据。那该怎么办呢?
我的守则是:
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://dev.bevbucks.com/gbs/api.json/token?user=rverma@prismetric.com&pwd=verma!pris"]];
NSURLResponse *response = nil;
NSError *error = nil;
//getting the data
NSData *newData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
//json parse
NSString *responseString = [[NSString alloc] initWithData:newData encoding:NSUTF8StringEncoding];
NSDictionary *jsonObject = [responseString JSONValue];
NSLog(@"type : %@", jsonObject ); 发布于 2013-03-07 13:25:57
返回的字符串:
"60ee094456b6fc03f386af50c443b471"不是有效的JSON,至少应该是:
[ "60ee094456b6fc03f386af50c443b471" ]因此,服务器中存在一个bug,而不是您的代码。如果您不能修复这个bug,那么您将不得不解决它。
来自JSON.org
JSON建立在两个结构上:
https://stackoverflow.com/questions/15272132
复制相似问题