我想在googleappengine上读取一个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);
它起作用了。我可以从我的应用程序引擎读取这些数据
^{pr2}$如果我把这些(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?在
简单答案:/
客户端站点(Android): 更换
与
^{pr2}$服务器站点上的这些(GAE和Python):
相关问题 更多 >
编程相关推荐