如何将此json字符串转换为java类对象? json String存储在数据库中,我需要转换为类对象。
{
"key1": {
"key11": "value11",
"key12": "value12",
"key13": "value13"
},
"key2": {
"key21": "value21",
"key22": "value22",
"key23": "value23"
},
"key3": "value3",
"key4": [{
"key1": {
"key11": "value11",
"key12": "value12",
"key13": "value13"
},
"key2": {
"key21": "value21",
"key22": "value22",
"key23": "value23"
}
}]
}
答案 0 :(得分:2)
您可以使用org.json资料库
JSONObject jsonObj = new JSONObject(string);
在您的情况下,从数据库中检索的字符串是
String string = {
"key1": {
"key11": "value11",
"key12": "value12",
"key13": "value13"
},
"key2": {
"key21": "value21",
"key22": "value22",
"key23": "value23"
},
"key3": "value3",
"key4": [{
"key1": {
"key11": "value11",
"key12": "value12",
"key13": "value13"
},
"key2": {
"key21": "value21",
"key22": "value22",
"key23": "value23"
}
}]
}