原生JSON解析数据

- (IBAction)touchReadButton:(id)sender {

    NSData *jsonData = [[NSData alloc] initWithContentsOfFile:JSON_PATH];
    NSError *error = nil;
    id jsonObject = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments error:&error;];

    if (jsonObject != nil && error == nil){
        NSLog(@"Successfully deserialized...");
        if ([jsonObject isKindOfClass:[NSDictionary class]]){
            NSDictionary *deserializedDictionary = (NSDictionary *)jsonObject;
            NSLog(@"Dersialized JSON Dictionary = %@", deserializedDictionary);
        } else if ([jsonObject isKindOfClass:[NSArray class]]){
            NSArray *deserializedArray = (NSArray *)jsonObject;
            NSLog(@"Dersialized JSON Array = %@", deserializedArray);
        } else {
            NSLog(@"An error happened while deserializing the JSON data.");
        }
    }
}
//该片段来自于http://outofmemory.cn

分析一下数码格式:

//原生JSON解析

(fastjson解析会起各个错乱问题)

JSONObject js = new JSONObject(result);

2

String result =
{“errorCode”:”0″,”info”:{“16″:[0,30],”17″:[0,30],”18″:[0,30],”19″:[0,30],”20″:[0,30],”21″:[0,30],”22″:[0,30],”23″:[0,30]},”msg”:”操作成”,”status”:”1″,”token”:””}

    JSONArray array =  js.getJSONArray(key);

    List list = JsonUtility.fromList(array.toString(), String.class);

Iterator it = js.keys();

while (it.hasNext()){

}

    mHourMaps.put(key, list);

    String key = String.valueOf(it.next());

//遍历jsonObject数据,添加到Map对象

TreeMap> mHourMaps = new TreeMap>();

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图