作为应用程序的一部分,我们正在开发(使用 android 客户端和 Django 服务器)一个包含用户名和密码的 json 对象从 android 客户端发送到服务器,如下所示
HttpPost post = new HttpPost(URL);
/*Adding key value pairs */
json.put("username", un);
json.put("password", pwd);
StringEntity se = new StringEntity(json.toString());
post.setEntity(se);
response = client.execute(post);
响应是这样解析的
result = responsetoString(response.getEntity().getContent()); //Converts response to String
jObject = new JSONObject(result);
JSONObject post = jObject.getJSONObject("post");
username = post.getString("username");
message = post.getString("message");
希望到此为止一切都很好。 在 Django 服务器中解析或发送 JSON 响应时会出现问题。执行此操作的最佳方法是什么?
我们尝试使用 SimpleJSON 并证明它不是那么简单,因为我们没有找到任何好的教程或示例代码?是否有任何类似于 get、put 和 opt in java for JSON 的 python 函数?任何帮助将不胜感激..
最佳答案
Python 标准库具有 JSON 加载/转储功能: http://docs.python.org/library/json.html
关于android - 在 Django 中处理 JSON 的最佳和简单方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2846321/