【发布时间】:2012-03-29 14:33:05
【问题描述】:
我想为我的 Android 设备编写一个嵌套的 JSON 对象,但是怎么做?我只有 Json 的基本经验,所以如果有人可以帮助我使用以下代码,我将不胜感激:
{
"command": "login",
"uid": "123123123",
"params":
{
"username": "sup",
"password": "bros"
}
}
编辑:
下面的代码确实解决了这个问题:
loginInformation = new ArrayList<NameValuePair>();
JSONObject parentData = new JSONObject();
JSONObject childData = new JSONObject();
try {
parentData.put("command", "login");
parentData.put("uid", UID.getDeviceId());
childData.put("username", username.getText().toString());
childData.put("password", password.getText().toString());
parentData.put("params", childData);
} catch (JSONException e) {
e.printStackTrace();
}
loginInformation.add(new BasicNameValuePair("content", parentData.toString()));
【问题讨论】:
-
您是否尝试使用 json 与服务通信?真的需要发这么难的结构吗?
-
你在开玩笑吗?发送嵌套的 JSON 对象有什么难的!?
-
正是我所需要的!!谢谢@Xarialon
-
@ArunJose 不客气!