相关疑难解决方法(0)

如何在Java中创建嵌套的Json对象?

我想为我的Android设备编写嵌套的JSON对象,但是如何?我只有Json的基本经验,所以如果有人可以帮助我使用以下代码,我将不胜感激:

{ 
 "command": "login",
 "uid": "123123123",
 "params":
  {
   "username": "sup",
   "password": "bros"
  }
}
Run Code Online (Sandbox Code Playgroud)

编辑:

以下代码确实解决了这个问题:

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()));
Run Code Online (Sandbox Code Playgroud)

android json

18
推荐指数
1
解决办法
2万
查看次数

标签 统计

android ×1

json ×1