import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
String Json = {"AccountToken":{"string":"hello"},"Event":{"string":"t"}}
JSONObject genreJsonObject =(JSONObject)JSONValue.parseWithException(json);
String account_id = (String) genreJsonObject.get("AccountToken");抛出java.lang.ClassCastException错误
有什么问题请帮忙吗?
发布于 2015-02-11 21:40:52
AccountToken是JSON对象,不是字符串.
您需要将其转换为JSONObject,并再次调用get(),以便从其内部结构中获得值。
String json = "{\"AccountToken\":{\"string\":\"hello\"},\"Event\":{\"string\":\"t\"}}";
JSONObject genreJsonObject =(JSONObject)JSONValue.parseWithException(json);
JSONObject accountToken = (JSONObject) genreJsonObject.get("AccountToken");
System.out.println(accountToken.get("string"));
==> hellohttps://stackoverflow.com/questions/28464721
复制相似问题