GAE从Android App读取JSON字符串

问题描述:

我想在Google App Engine上读取JSON字符串(从我的Android应用获取)。 但我不知道如何解决这个问题。GAE从Android App读取JSON字符串

这是从我的应用程序的代码:

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)我可以

getPostData = self.request.body 

阅读我的应用程序引擎这些数据拿出

{\"datumende\":\"27.4.2012\",\"user\":\"peter\",\"frage\":\"frage1\"} 

而且它的工作原理。

但是我怎样才能将JSON字符串拆分为用户,datumende和frage? 我与

x = json.dumps(self.request.body) 
y = json.loads(x) 
# I thougt in y['user'] is now "peter". But it isnt't 

testet还我testet只

x = json.laods(self.request.body) 
# I thougt in x['user'] is now "peter". But it isnt't 

但这一切不工作。 那么,如何将JSON字符串拆分为用户,frage,datumende?

简单的answere:/

客户站点(安卓): 更换

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

connection.setRequestProperty("Content-Type", "application/json"); 

而这些在服务器站点(GAE与Python):

lo = self.request.body 
fff = json.loads(lo) 
name = fff['user']