String json = "{\"id\":123,\"name\":\"小明\",\"address\":\"{\"pro\":\"北京\",\"city\":\"北京市\"}\"}";
Object o = (Object)json;
String tmp = o.toString();
JSONObject jo = JSONObject.parseObject(tmp);
Object address = jo.get("address");
String a = address.toString();
System.out.println(jo.toString());
3条答案
按热度按时间afdcj2ne1#
你描述问题好歹也要贴个代码上来吧,你这样一说鬼知道怎么解决
oogrdqng2#
sorry,是有样例代码的,估计提的时候操作失误。现在问题已更新。
w8biq8rn3#
你的JSON格式错了,正确格式如下,而且我搞不懂转个JSON为什么要强转成Object?
public static void main(String[] args) {
String json = "{"id":123,"name":"小明","address": {"pro":"北京","city":"北京市"} }";
Object o = (Object)json;
String tmp = o.toString();
JSONObject jo = JSONObject.parseObject(tmp);
Object address = jo.get("address");
String a = address.toString();
System.out.println(jo.toString());
}