我有这个JSON数据,我在发送JSON请求后作为响应收到。我想将这些数据存储在持久存储内存或文件中,然后稍后再读回来并作为下拉列表显示在我的屏幕上。如果有人知道如何在Codename One中,我将不胜感激。
{
result_code=0.0,
data= [
{
id=1,
title=Afghanistan
},
{
id=2,
title=Albania
},
{
id=3,
title=Algeria
},
{
id=4,
title=Andorra
},
{
id=5,
title=Angola
},
{
id=6,
title=Antigua And Barbuda
},
],
message=OK
}
答案 0 :(得分:2)
我刚做了一个小测试(y)
String x = "{result_code=0.0,data= [{id=1, title=Afghanistan }, { id=2, title=Albania }, { id=3, title=Algeria }, { id=4, title=Andorra }, { id=5, title=Angola }, { id=6, title=Antigua And Barbuda }, ], message=OK }";
Storage.getInstance().writeObject("abcd.txt", x);
Object rawString = Storage.getInstance().readObject("abcd.txt");
JSONObject jsonObject = new JSONObject(rawString.toString());
JSONArray data = (JSONArray) jsonObject.get("data");
Double resultCode = Double.valueOf(jsonObject.getDouble("result_code"));
String message = jsonObject.get("message").toString();
// TODO: JSON parsing
JSONObject firstObjectFromArray = data.getJSONObject(0);
// TODO: do somestuff in a loop and put into combobox?
firstObjectFromArray.get("id");
firstObjectFromArray.get("title");
编辑:你说的是组合框组件?