我想在Android代码中创建此字符串。我想从我的webservice获取当前和存储的lat日志。
{"request":
{
"from": "$UDID",
"with":
{
"action": "GET_DETAILSTORE",
"device":
{
"id": "$UDID",
"time": "1234567890"
},
"data":
{
"cat_id":"1",
"more":"10",
"currentLat":"23.0333",
"currentLong":"72.6167"
}
}
}
}
答案 0 :(得分:1)
您可以从上面的字符串中获取数据,如下所示:
String strResponse = "YOUR_ABOVE_STRING";
JSONTokener tokener = new JSONTokener(strResponse);
JSONObject finalResult = new JSONObject(tokener);
JSONObject objRequest = finalResult.getJSONObject("request");
Log.i("from",objRequest.getJSONString("from"));
JSONObject objWith = objRequest.getJSONObject("with");
Log.i("action",objWith.getJSONString("action"));
JSONObject objDevice = objWith.getJSONObject("device");
Log.i("id",objDevice.getJSONString("id"));
Log.i("time",objDevice.getJSONString("time"));
JSONObject objData = objWith.getJSONObject("data");
Log.i("cat_id",objData.getJSONString("cat_id"));
Log.i("more",objData.getJSONString("more"));
Log.i("currentLat",objData.getJSONString("currentLat"));
Log.i("currentLong",objData.getJSONString("currentLong"));
现在您可以使用来自Web服务的json格式的字符串中的任何数据。
希望它会对你有所帮助。