json 배열 문자열 집합

3996 단어 JAVA
package com.zkn.newlearn.json;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
 
import java.util.List;
import java.util.Map;
 
/**
 * Created by zkn on 2016/8/22.
 */
public class JsonToMapTest02 {
 
    public static void main(String[] args){
 
        String strArr = "[{\"0\":\"zhangsan\",\"1\":\"lisi\",\"2\":\"wangwu\",\"3\":\"maliu\"}," +
                "{\"00\":\"zhangsan\",\"11\":\"lisi\",\"22\":\"wangwu\",\"33\":\"maliu\"}]";
        //     
        List> listObjectFir = (List>) JSONArray.parse(strArr);
        System.out.println("  JSONArray  parse     json     ");
        for(Map mapList : listObjectFir){
            for (Map.Entry entry : mapList.entrySet()){
               System.out.println( entry.getKey()  + "  " +entry.getValue());
            }
        }
        //     
        List> listObjectSec = JSONArray.parseObject(strArr,List.class);
        System.out.println("  JSONArray  parseObject            json     ");
        for(Map mapList : listObjectSec){
            for (Map.Entry entry : mapList.entrySet()){
                System.out.println( entry.getKey()  + "  " +entry.getValue());
            }
        }
        //     
        JSONArray listObjectThir = JSONArray.parseArray(strArr);
        System.out.println("  JSONArray  parseArray     json     ");
        for(Object mapList : listObjectThir){
            for (Object entry : ((Map)mapList).entrySet()){
                System.out.println(((Map.Entry)entry).getKey()  + "  " +((Map.Entry)entry).getValue());
            }
        }
        //     
        List listObjectFour = JSONArray.parseArray(strArr,Map.class);
        System.out.println("  JSONArray  parseArray            json     ");
        for(Object mapList : listObjectFour){
            for (Object entry : ((Map)mapList).entrySet()){
                System.out.println(((Map.Entry)entry).getKey()  + "  " +((Map.Entry)entry).getValue());
            }
        }
        //     
        JSONArray listObjectFifth = JSONObject.parseArray(strArr);
        System.out.println("  JSONObject  parseArray     json     ");
        for(Object mapList : listObjectFifth){
            for (Object entry : ((Map)mapList).entrySet()){
                System.out.println(((Map.Entry)entry).getKey()  + "  " +((Map.Entry)entry).getValue());
            }
        }
        //     
        List listObjectSix = JSONObject.parseArray(strArr,Map.class);
        System.out.println("  JSONObject  parseArray            json     ");
        for(Object mapList : listObjectSix){
            for (Object entry : ((Map)mapList).entrySet()){
                System.out.println(((Map.Entry)entry).getKey()  + "  " +((Map.Entry)entry).getValue());
            }
        }
        //     
        JSONArray listObjectSeven = JSON.parseArray(strArr);
        System.out.println("  JSON  parseArray     json     ");
        for(Object mapList : listObjectSeven){
            for (Object entry : ((Map)mapList).entrySet()){
                System.out.println(((Map.Entry)entry).getKey()  + "  " +((Map.Entry)entry).getValue());
            }
        }
        //     
        List listObjectEigh = JSONObject.parseArray(strArr,Map.class);
        System.out.println("  JSON  parseArray            json     ");
        for(Object mapList : listObjectEigh){
            for (Object entry : ((Map)mapList).entrySet()){
                System.out.println(((Map.Entry)entry).getKey()  + "  " +((Map.Entry)entry).getValue());
            }
        }
    }
}

다음으로 이동:https://gitee.com/wefashe/codes/jrvmqy5opfsgktw4089i110

좋은 웹페이지 즐겨찾기