向json android添加字符

向json android添加字符,android,Android,我有以下问题。我必须发送以下json 为此,我使用了json.put()方法,然后是json.acummulate(“d”,JsonObject) 正如我所能做的,给我以下的结果 当我添加两个数据函数“[”。我需要以这种方式发送它,因为我无法更改服务器上的脚本 我曾经使用json.append.将当前jsonObject创建为: //Create main json object JSONObject json = new JSONObject(); //Create d JSONArra

我有以下问题。我必须发送以下json

为此,我使用了json.put()方法,然后是json.acummulate(“d”,JsonObject)

正如我所能做的,给我以下的结果

当我添加两个数据函数“[”。我需要以这种方式发送它,因为我无法更改服务器上的脚本


我曾经使用json.append.

将当前jsonObject创建为:

//Create main json object
JSONObject json = new JSONObject();

//Create d JSONArray
JSONArray dJsonarray = new JSONArray();

// Create JSONObject
JSONObject djson = new JSONObject();
// put value inside d json object
dJson.put("fa", "12");
dJson.put("nt", "37537.6015625");
dJson.put("ca", "1");
dJson.put("a", "4692.2001953125");
dJson.put("p", "4692.2001953125");
dJson.put("a", "1116861");

// put JSONObject to json Array
dJsonarray.put(dJson);    

//put tn key-value in json object
json.put("tn","37537.6015625");
//put d json object name-value in json object
json.put("d",dJsonarray);

并且无需调用,因为此方法将值附加到已映射到名称的数组。因为您要发送到服务器的主json字符串只有jsonObject

@user2014065:您能告诉我为什么它不工作吗,因为这是根据您的question@user2014065当前位置正如你所说的,我必须把foll由于json
tosend={“tn”:37537.6015625,“d”:{“fa”:12,“nt”:37537.6015625,“ca”:1,“a”:4692.2001953125,“p”:4692.2001953125,“a”:1116861},“tb”:-27182.3984375}。
然后我的答案创建了你想要发送的相同结构的json对象。那么问题出在哪里?好的,我的错。我必须发送以下字符串tosend={“tn”:37537.6015625,“d”:[{“Fa”:12,“nt”:37537.6015625,“ca”:1,“a”:4692.2001953125,“p”:4692.2001953125,“a”:1116861},“Tb”:-27182.3984375}。我无法添加字符[。我尝试使用json.put(“d”,“[“+detalepidedojson+”]),但没有添加任何字符
 tosend = {"tn": 37537.6015625,
"d":
[{"Fa": 12, "nt": 37537.6015625, "ca": 1, "a": 4692.2001953125, "p": 4692.2001953125, "a": 1116861}
], "Tb": -27182.3984375}.
//Create main json object
JSONObject json = new JSONObject();

//Create d JSONArray
JSONArray dJsonarray = new JSONArray();

// Create JSONObject
JSONObject djson = new JSONObject();
// put value inside d json object
dJson.put("fa", "12");
dJson.put("nt", "37537.6015625");
dJson.put("ca", "1");
dJson.put("a", "4692.2001953125");
dJson.put("p", "4692.2001953125");
dJson.put("a", "1116861");

// put JSONObject to json Array
dJsonarray.put(dJson);    

//put tn key-value in json object
json.put("tn","37537.6015625");
//put d json object name-value in json object
json.put("d",dJsonarray);