天天看點

從Json中擷取字段資料

從Json中擷取字段資料

代碼如下

import com.alibaba.fastjson.JSONObject;

public class Json {
    public static void main(String[] args) {
        JSONObject jsb = new JSONObject();
        jsb.put("empid","123");
        System.out.println("------------->"+jsb);
        JSONObject jsonObject = JSONObject.parseObject(String.valueOf(jsb));
        String empid = jsonObject.get("empid").toString();
        System.out.println("------------->"+empid);
    }
}
           

傳回結果如下:

從Json中擷取字段資料
輸出結果:
------------->{"empid":"123"}
------------->123