com.alibaba.fastjson 把JSONObject转换为Map(String, Integer)对象

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;

JSONObject obj = new JSONObject();
{
obj.put("key1", "value1");
obj.put("key2", "value2");
obj.put("key3", "value3");
}
Map<String, Integer> params = JSONObject.parseObject(obj.toJSONString(), new TypeReference<Map<String, Integer>>(){});
System.out.println(params);

//输出:{key3=value3, key2=value2, key1=value1}

List<FlowoutHotel>   flowoutList = JSONObject.parseObject(v, new TypeReference<List<FlowoutHotel>>() { });

<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>fastjson</artifactId>
    <version>1.2.61</version>
</dependency>
发布了77 篇原创文章 · 获赞 182 · 访问量 58万+

猜你喜欢

转载自blog.csdn.net/hellojoy/article/details/104647946