使用JAVA POST方法发送时,JSON对象格式在服务器上无效

时间:2014-07-08 13:35:36

标签: json

我正在创建一个JSON对象,如下所示 -

    JSONObject jsonData = new JSONObject();
    JSONArray arr = new JSONArray();
    try {
          if (cursor.moveToFirst()) {
            do {
                Log.d("buildReportAsString",
                        "cursor.getString(3)" + cursor.getString(3));
                String data = cursor.getString(3);
                if (data != null) {
                    JSONObject obj = new JSONObject(data);

                    arr.put(obj);
                }
            } while (cursor.moveToNext());
        }
        Log.d("buildReportAsString", "arr is " + arr);
        jsonData.put("events", arr);

    } catch (JSONException je) {
        Log.d(TAG, "JSON Exception is" + je);
    }

我打印它似乎是正确的json格式,但是当我在服务器上看到它时,json格式无效,因为所有逗号都消失了。 客户端 -

    {
"events":[
{
    "timestamp":1404819090958,
    "minBatchSize":50,
    "freq":15
},
{
    "timestamp":1404819089917,
    "value":0.2175,
    "topProcess":"system"
},
{
    "timestamp":1404819091157,
    "CacheMemory":130876,
    "SwapMemory":0
}

        ]
}

但是在我在服务器上看到这个json数据后,所有逗号都消失了,它看起来像Jbelow -

    {
    "events": [
        {
"timestamp": 1404823898222
"minBatchSize": 100
"freq": 168
}
{
"value": 0.155
"timestamp": 1404824016366
 "topProcess": "kthreadd"
    "topProcessLoad": 0

    }
    ]
    }

有人能告诉我什么是错的吗?在发送JSON对象之前我需要做什么设备端?我正在使用POST请求。

1 个答案:

答案 0 :(得分:0)

您可以查看发布数据的内容类型吗?

它应该是

类型
  

"应用/ JSON"