- <pre name="code" class="java"><pre name="code" class="java">1.将字典或者数组反序列化为NSString.
- NSMutableDictionary *jsonDic = [NSMutableDictionary dictionary];
- NSMutableDictionary *alert = [NSMutableDictionary dictionary];
- NSMutableDictionary *aps = [NSMutableDictionary dictionary];
- [alert setObject:@"a msg come!" forKey:@"body"];
- [aps setObject:alert forKey:@"alert"];
- [aps setObject:@"3" forKey:@"bage" ];
- [aps setObject:@"def.mp3" forKey:@"sound"];
- [jsonDic setObject:aps forKey:@"aps"];
- NSString *strJson = [jsonDic JSONString];
- NSLog(@"%@",strJson);
- // 2.将NSString反序列化为数组、字典.
- NSDictionary *result = [strJson objectFromJSONString];
- // 或者
- NSDictionary *result = [dataJson objectFromJSONData];
- NSLog(@"%@",result);</pre><br>
- NSError *error;NSString *textFileContents = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"json" ofType:@"txt"] encoding:NSUTF8StringEncoding error:&error];if (textFileContents == nil) {NSLog(@"Error reading text file. %@", [error
- localizedFailureReason]);}NSDictionary *result = [textFileContents objectFromJSONString];NSLog(@"res= %@", [result objectForKey:@"cmd"]);
- <pre></pre>
- <br>
- <br>
- <pre></pre>
- <p>读取jsonKIT文件,转化成json字典</p>
- <p><br>
- </p>
- </pre>
stirng 读取json文件 jsonkit 使用
最新推荐文章于 2024-09-23 11:57:38 发布