json字符串转java map
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了json字符串转java map相关的知识,希望对你有一定的参考价值。
形如这样的var json= "people": [ "firstName": "Brett", "lastName":"McLaughlin", "email": "brett@newInstance.com" , "firstName": "Jason", "lastName":"Hunter", "email": "jason@servlets.com" , "firstName": "Elliotte", "lastN1ame":"Harold", "email": "elharo@macfaq.com" ];,传递到后台怎么转化成map或list啊
例子网上有N多,我想说的是你jar包不导齐什么都干不了,附图:
public void toPerson()
String json = "'people':['data1':100,'data2':'hello','id':1]";
Gson gson = new Gson();
Person p = gson.fromJson(json, HashMap.class)
public void toJsonString()
Person p = new Person();
p.setId(1);
Gson gson = new Gson();
String s = gson.toJson(p,Person.class);
System.out.println("s"+s);
参考技术B for (int i = 0; i < ja.size(); i++)
JSONObject jasonObject = JSONObject.fromObject(ja.get(i));
Map<String, Object> map2 = (Map) jasonObject;
System.out.print(map2.get("name") + ",");
System.out.println(map2.get("id"));
本回答被提问者采纳
以上是关于json字符串转java map的主要内容,如果未能解决你的问题,请参考以下文章