下面是我的代码。我仍然需要添加“ studentInfo”字段。
JSONObject jo = new JSONObject();
jo.put("name", "ALEX JAMES");
jo.put("id", "22284666");
jo.put("age","13")
要创建的JSON正文消息:
{
"body": {
"studentInfo": {
"name": "ALEX JAMES",
"id": "22284666",
"age": "13"
}
}
}
你可以嵌套对象
JSONObject studentInfo = new JSONObject();
studentInfo.put("name", "ALEX JAMES");
studentInfo.put("id", "22284666");
studentInfo.put("age","13");
JSONObject body = new JSONObject();
body.put("studentInfo" , studentInfo);
JSONObject wrapper = new JSONObject();
wrapper.put("body" , body);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句