Converting Map into json

前端 未结 4 1878
长情又很酷
长情又很酷 2021-02-15 16:40

I have Map in java like this :

{card_switch=Master, issuing_bank=ICCI, card_Type=DebitCard}

I\'m using the s

4条回答
  •  灰色年华
    2021-02-15 17:33

    Have a look at example 1.4 on this page http://code.google.com/p/json-simple/wiki/EncodingExamples#Example_1-4_-_Encode_a_JSON_object_-_Using_Map_and_streaming:

     Map obj=new LinkedHashMap();
       obj.put("name","foo");
       obj.put("num",new Integer(100));
       obj.put("balance",new Double(1000.21));
       obj.put("is_vip",new Boolean(true));
       obj.put("nickname",null);
       StringWriter out = new StringWriter();
       JSONValue.writeJSONString(obj, out);
       String jsonText = out.toString();
       System.out.print(jsonText);
    

提交回复
热议问题