转自:http://blog.csdn.net/feelwing1314/article/details/24305759
JSON解析器fastjson(阿里巴巴出品,版本1.1.26),如果定义了JSONObject为{"JACKIE_ZHANG":"张学友","ANDY_LAU":"刘德华","LIMING":"黎明","Aaron_Kwok":"郭富城"},那么读取值时,KEY顺序无序,测试代码:
- importcom.alibaba.fastjson.JSONObject;
- /**
- *Createdbywangzhenfeion14-4-15.
- */
- publicclassFastJsonTest{
- staticvoidmain(String[]args){
- StringjsonStr="{\"JACKIE_ZHANG\":\"张学友\",\"ANDY_LAU\":\"刘德华\",\"LIMING\":\"黎明\",\"Aaron_Kwok\":\"郭富城\"}";
- //做5次测试
- for(inti=0,j=5;i<j;i++)
- {
- JSONObjectjsonObject=JSONObject.parSEObject(jsonStr);
- for(java.util.Map.Entry<String,Object>entry:jsonObject.entrySet()){
- System.out.print(entry.getKey()+"-"+entry.getValue()+"\t");
- }
- System.out.println();//用来换行
- }
- }
运行结果: