在我的iOS 5应用程序中,我有一个包含JSONstring的NSString 。 我想将该JSONstring表示反序列化为本机NSDictionary对象。 "{\"password\" : \"1234\", \"user\" : \"andreas\"}" 我尝试了以下方法: NSDictionary *json = [NSJSONSerialization JSONObjectWithData:@"{\"2\":\"3\"}" options:NSJSONReadingMutableContainers error:&e]; 但它会引发运行时错误。 我究竟做错了什么? -[__NSCFConstantString bytes]: unrecognized selector sent to instance 0x1372c *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString bytes]: unrecognized selector sent to instance 0x1372c'
我努力尝试sorting字典数组。 我的字典有一些价值的兴趣,价格,知名度等 有什么build议么?
我有一个字典arrays。 我想根据一个键过滤数组。 我试过这个: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(SPORT == %@)", @"Football"]; NSArray *filteredArray = [data filteredArrayUsingPredicate:predicate]; 这不行,我没有结果。 我觉得我做错了什么。 我知道这是“体育”是伊娃的方法。 如果它是一个关键,我认为它可能是不同的。 但是我还没有find一个例子。 谢谢 更新 我在我正在search的string周围添加引号。 NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(SPORT == '%@')", @"Football"]; 它仍然不起作用。 更新2 解决了它。 我实际上已经删除了单引号,这似乎违背了指南的说法。 我真正的问题是我有一个嵌套的数组,我实际上没有评估字典。 骨头移动。
我有一个JSONstring(来自PHP的json_encode() ,看起来像这样: [{"id": "1", "name":"Aaa"}, {"id": "2", "name":"Bbb"}] 我想parsing这个到我的iPhone应用程序的某种数据结构。 我想对我来说最好的办法是有一个字典数组,因此数组中的第0个元素是一个字典,其中键为"id" => "1"和"name" => "Aaa" 。 我不明白NSJSONSerialization如何存储数据。 这是我的代码到目前为止: NSError *e = nil; NSDictionary *JSON = [NSJSONSerialization JSONObjectWithData: data options: NSJSONReadingMutableContainers error: &e]; 这只是我在其他网站上看到的一个例子。 我一直试图通过打印出这样的元素数量和类似的东西来读取JSON对象,但我总是得到EXC_BAD_ACCESS 。 我如何使用NSJSONSerializationparsing上面的JSON,并将其转换为我提到的数据结构?