Java代码中获取Json的key值

时间:2021-12-18 05:48:16

测试json字符串:

{"access_token":"hkbQl5o_l67dZ7_vJRATKBwTLk9Yj5QyMuOJThAr8Baj0xWf4wxW1p4ym4iTZ3-ptWRRoVtbCNJnyjGLfed_4bB0HiqGP8v-aXOJUUk1tFs","expires_in":7200,"refresh_token":"_or_31yEp8XhxGWvrAzdWIkXfFlKjfb3iTRpfaN_3kPAVQAPLW6PaW_zmO4GSkC2R0QxqsyJrvLVbDrq4PW9JALi7S6PB8g8yWSwo-PcBqs","openid":"o7jBjwzBUESlQnlLQy_UR25BJe3o","scope":"snsapi_base"}

Java代码中获取:

JSONObject jsonObj=JSONObject.parseObject(openId);
String openid=jsonObj.getString("openid");

jsp中获取:

先后台设置:mv.addObject("tributes",JSON.toJSON("字符串"));---springMVC、(import com.alibaba.fastjson.*)

前台:JSON.parse('${tributes}');