Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/187.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
GAE从Android应用程序读取JSON字符串_Android_Python_Json - Fatal编程技术网

GAE从Android应用程序读取JSON字符串

GAE从Android应用程序读取JSON字符串,android,python,json,Android,Python,Json,我想在谷歌应用程序引擎上读取一个JSON字符串(从我的Android应用程序获取)。 但我不知道如何解决这个问题 以下是我的应用程序中的代码: JSONObject ob = new JSONObject(); ob.put("user", "peter"); ob.put("frage", "frage1"); ob.put("datumende", "27.4.2012"); Log.i("json", ob.toString()); con

我想在谷歌应用程序引擎上读取一个JSON字符串(从我的Android应用程序获取)。 但我不知道如何解决这个问题

以下是我的应用程序中的代码:

    JSONObject ob = new JSONObject();
    ob.put("user", "peter");
    ob.put("frage", "frage1");
    ob.put("datumende", "27.4.2012");
    Log.i("json", ob.toString());

    connection.setRequestMethod("POST");
    connection.setRequestProperty("Content-Type",
            "application/x-www-form-urlencoded");

    connection.setRequestProperty("Content-Language", "en-US");

    connection.setUseCaches(false);
    connection.setDoInput(true);
    connection.setDoOutput(true);

    byte[] outputBytes = ob.toString().getBytes("UTF-8");
    connection.setRequestProperty("Content-Length", Integer.toString(outputBytes.length));
    OutputStream os = connection.getOutputStream();
    os.write(outputBytes);
它起作用了。我可以从我的应用程序引擎中读取这些数据

getPostData = self.request.body
如果我在数据存储器中写入这些(getPostData),它就会输出

{\"datumende\":\"27.4.2012\",\"user\":\"peter\",\"frage\":\"frage1\"}
它也能工作

但如何将JSON字符串拆分为user、datumende和frage? 我已经测试过了

x = json.dumps(self.request.body)
y = json.loads(x)
# I thougt in y['user'] is now "peter". But it isnt't
而且我只测试了它

x = json.laods(self.request.body)
# I thougt in x['user'] is now "peter". But it isnt't
但这一切都不起作用。 那么,如何将JSON字符串拆分为user、frage、datumende?

简单answere:/

客户端站点(Android): 替换

在服务器站点上(使用Python的GAE):

connection.setRequestProperty("Content-Type",
        "application/x-www-form-urlencoded");
connection.setRequestProperty("Content-Type", "application/json");
lo = self.request.body
fff = json.loads(lo)
name = fff['user']