Best and simple way to handle JSON in Django

Posted by primal on Stack Overflow See other posts from Stack Overflow or by primal
Published on 2010-05-17T02:18:18Z Indexed on 2010/05/17 2:20 UTC
Read the original article Hit count: 289

Filed under:
|
|
|

Hi,

As part of the application we are developing (with android client and Django server) a json object which contains user name and pass word is sent to server from android client as follows

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);

The response is parsed like this

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");

Hope upto this everything is fine. The problem comes when parsing or sending JSON responses in Django server. Whats the best way to do this?

We tried using SimpleJSON and it turned out not to be so simple as we didn't find any good tutorials or sample code for the same? Are there any python functions similiar to get,put and opt in java for JSON? Any help would be much appreciated..

© Stack Overflow or respective owner

Related posts about JSON

Related posts about django