Java HashMap Transform js json Formal

background

We are developing Android-like individual demand, and Android-like local demand sum WebView-like javascript-like api progress alternating. The javascript-like alternating number setting is usually the jason form, and the reason is the demand grasping java medium-based object number setting. Immediate problem, javascript-like copying method comparison, direct copying, one-step character string, self-remembering key, 针 opposite 每 one-in-one key, 你 子 Can copy self-remembering number setting formula, ratio, object, number, etc. .. However, it is a request for java, and it is not possible to change it.

スクリーンショット 2018-01-09 11.57.49.png

Immediately, we are the most intelligent and simplest method. HashMap sum JSONObject Typological syllabary, typological syllabary, jason-like variable amount, HashMap typologically, reusable JSONObject, typologically, json, and json.

スクリーンショット 2018-01-09 14.11.50.png

convert.java


        //first you construct the HashMap data
        HashMap<String,Object> hashmap = new HashMap<String,Object>();
        hashmap.put("name","syoui");
        hashmap.put("age",27);
        int[] checkInList = {1,3,5,7,8,10,12};
        hashmap.put("checkInList",checkInList);

        //second you convert the HashMap data into String json data
        JSONObject jsonObject = new JSONObject(hashmap);
        Log.d("the convert result",jsonObject.toString());

Result of Nisshi D/the convert result: {"name":"syoui","checkInList":[1,3,5,7,8,10,12],"age":27}

In addition, HashMap-like support, HashMap-like, this type of stipulation, one key, bottom surface re-subjection, HashMap-like explanation, HashMap-like copying method

convert.java


        HashMap<String,Object> sub_hash_map = new HashMap<String,Object>();
        sub_hash_map.put("name","liaoliao");
        sub_hash_map.put("age",30);
        int[] sub_check_list = {2,4,6,9,11};
        sub_hash_map.put("checkInList",sub_check_list);
        hashmap.put("child",sub_hash_map);

Result of Nisshi D/the convert result: {"name":"syoui","ticket":null,"age":27,"child":{"name":"liaoliao","checkInList":[2,4,6,9,11],"age":30},"checkInList":[1,3,5,7,8,10,12]}

Recommended Posts

Java HashMap Transform js json Formal
Java HashMap class
Read JSON in Java
Read Java HashMap source
POST JSON in Java
Create JSON in Java
Initializing HashMap in Java
[Java] JSON communication with jackson
POST Json in Java ~ HttpURLConnection ~
Json serialization / deserialization in Java 1.4
Java HashMap, entrySet [Personal memo]
Java, JS (jQuery) and Ajax. Get a specific value of JSON.