使用FastJson从json串中根据key获取value

 1 import com.alibaba.fastjson.JSONObject;
 2 
 3 /**
 4  * Created by SYJ on 2017/9/13.
 5  */
 6 public class MainTest {
 7     public static void main(String[] args) {
 8         String json = "{\"code\":0,\"message\":\"没有查询到数据\",\"data\":null,\"taskId\":\"0-bb03193f-ed1f-4d32-8351-6538d329b26e\",\"time\":\"2017-09-2210:11:30\"}";
 9         JSONObject obj = JSONObject.parseObject(json);
10         Integer code = obj.getInteger("code");
11         String message = obj.getString("message");
12         String taskId = obj.getString("taskId");
13 
14         System.out.println("code:" + code + ", message:" + message + ", taskId:" + taskId);
15     }
16 }

 

posted @ 2017-09-22 14:34  xuebusi  阅读(16239)  评论(0编辑  收藏  举报