小编Jim*_*mit的帖子

通过Android中的HTTP put请求将JSON发送到服务器

如何将给定的json包装到字符串并通过Http put请求将其发送到服务器?

这就是我的json的样子.

    {
    "version": "1.0.0",
    "datastreams": [
        {
            "id": "example",
            "current_value": "333"
        },
        {
            "id": "key",
            "current_value": "value"
        },
        {
            "id": "datastream",
            "current_value": "1337"
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

上面是我的json数组.

下面是我编写代码的方法,但它不起作用

        protected String doInBackground(Void... params) {
            String text = null;
            try {
                JSONObject child1 = new JSONObject();
                try{
                    child1.put("id", "LED");
                    child1.put("current_value", "0");


                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }


                JSONArray jsonArray = new JSONArray();

                jsonArray.put(child1);

                JSONObject datastreams = new JSONObject();
                datastreams.put("datastreams", jsonArray);  

                JSONObject version = new …
Run Code Online (Sandbox Code Playgroud)

android json xively

5
推荐指数
1
解决办法
3万
查看次数

标签 统计

android ×1

json ×1

xively ×1