首先,为我的英语而痛哭…:)
我使用的是YAJL框架http://github.com/gabriel/yajl-objc
我的文件如下所示:
[ [ 3753700,
{ "altitude" : 36950,
"heading" : 129.918421384319,
"latitude" : 47.554033252495699,
"longitude" : 8.2125612837369903,
"pointType" : "EXTRAPOLATED",
"speed" : 455.04395392093699,
"timestamp" : 1273252673301,
"verticalRate" : 0.0
}
],
[ 3753700,
{ "altitude" : 36950,
"heading" : 129.918421384319,
"latitude" : 47.552708437680799,
"longitude" : 8.2149074662342798,
"pointType" : "EXTRAPOLATED",
"speed" : 455.04395392093699,
"timestamp" : 1273252674555,
"verticalRate" : 0.0
}
]
]我在x-variant中尝试过,但我总是从控制台得到一个'NSInvalidArgumentException‘:
2010-05-07 20:17:30.998 testApp[2365:207] *** -[NSConcreteData yajl_JSON]: unrecognized selector sent to instance 0x1353d0
2010-05-07 20:17:31.006 testApp[2365:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSConcreteData yajl_JSON]: unrecognized selector sent to instance 0x1353d0'如何正确读取数据?
thx请求帮助
发布于 2010-05-09 23:10:19
我不知道您正在使用的框架,但您尝试过Google Code上可用的json-framework吗?我在几个项目中使用过它,从来没有遇到过任何问题。
+ (NSString *)stringWithUrl:(NSURL *)url {
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url
cachePolicy:NSURLRequestReturnCacheDataElseLoad
timeoutInterval:30];
NSData *urlData;
NSURLResponse *response;
NSError *error;
urlData = [NSURLConnection sendSynchronousRequest:urlRequest
returningResponse:&response
error:&error];
return [[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding];
}
+ (id)objectWithUrl:(NSURL *)url {
SBJSON *jsonParser = [SBJSON new];
NSString *jsonString = [self stringWithUrl:url];
return [jsonParser objectWithString:jsonString error:NULL];
}使用这些方法,您可以轻松地调用[YourJSONHelperClass objectWithUrl:yourServiceUrl],它将返回一个NSDictionary。
hth
-f
发布于 2010-05-08 10:06:55
您是否将‘-ObjC’和‘-load_all’命令添加到您的目标的链接器标志中?如果它们不存在,则静态库中存在的类别在编译后的二进制文件中将不可用。
在文档中:在目标中的“Other Linker Flags”下,添加-ObjC和-all_load (因此加载了NSObject+YAJL类别)。
https://stackoverflow.com/questions/2790831
复制相似问题