/**
* Parse a JSON-formatted string into a map object <li>
* JSON format: {"name": "admin", "retries": "3fff", "TestName"
*: "ddd", "testretries": "Fffffffff"}
*/
Private static hashmap<string, string> tohashmap (Object object)
{
hashmap<string, string> data = new hashmap<string, string> ();
//Convert JSON string to Jsonobject
Jsonobject Jsonobject = Jsonobject.fromobject (object);
Iterator it = Jsonobject.keys ();
//Traverse jsonobject data, add to map object
while (It.hasnext ())
{
String key = String.valueof (It.next ());
String value = (string) jsonobject.get (key);
Data.put (key, value);
}
return data;
}
Convert list to JSON data:
list<userinfo> list = new arraylist<userinfo> ();
UserInfo user = new UserInfo (1001, "Zhang San");
List.add (user);
List.add (user);
List.add (user);
Jsonarray Jsonarray = jsonarray.fromobject (list);
System.out.println (Jsonarray);
650) this.width=650; "Src=" https://app.yinxiang.com/shard/s69/share/683-s69/res/ C862685c-20fb-48a0-8e3e-f150851a89b0.png "Name=" c862685c-20fb-48a0-8e3e-f150851a89b0 "class=" En-media "style=" Margin:.857412em 0px 1.286em;padding:0px;border:0px;height:auto; "/>
To convert the map to JSON, use the Jsonobject object:
map<string, object> map = new hashmap<string, object> ();
Map.put ("UserId", 1001);
Map.put ("UserName", "Zhang San");
Map.put ("Usersex", "male");
Jsonobject jsonobject = jsonobject.fromobject (map);
System.out.println (Jsonobject);
650) this.width=650; "Src=" https://app.yinxiang.com/shard/s69/share/683-s69/res/ 9d39a227-6007-43fb-9e59-41922803fc4f.png "class=" En-media "style=" Margin:.857412em 0px 1.286em;padding:0px;border : 0px;height:auto; "/>
Http://jingyan.baidu.com/article/1709ad80b780f04634c4f0d9.html
Object into JSON:
UserInfo user = new UserInfo (1001, "Zhang San");
Jsonarray Jsonarray = jsonarray.fromobject (user);
System.out.println (Jsonarray)
650) this.width=650; "Src=" https://app.yinxiang.com/shard/s69/share/683-s69/res/ 750494aa-40c9-4160-999b-dc32bd7580ae.png "class=" En-media "style=" Margin:.857412em 0px 1.286em;padding:0px;border : 0px;height:auto; "/>;
To convert an array to JSON:
String[] arr = {"ASD", "DFGD", "ASD", "234"};
Jsonarray Jsonarray = Jsonarray.fromobject (arr);
System.out.println (Jsonarray);
650) this.width=650; "Src=" https://app.yinxiang.com/shard/s69/share/683-s69/res/52715558- C3f9-4584-9f7b-0885cbf10d57.png "class=" En-media "style=" Margin:.857412em 0px 1.286em;padding:0px;border:0px; Height:auto; "/>
Parse a JSON-formatted string into a map object