I use Volley library in android and create a JsonObjectRequest like this:
String JsonUrl = "192.168.1.3/json.py";
JsonObjectRequest jsObjRequest = new JsonObjectRequest
(Request.Method.GET, JsonUrl, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
mTextView.setText("Json Response: " + response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
mTextView.setText("Error in recieving JSON Response");
}
});
// Access the RequestQueue through your singleton class.
MySingleton.getInstance(this).addToRequestQueue(jsObjRequest);
and this is my Python Code (json.py):
import json
pythonDictionary = {'name':'Bob', 'age':44, 'isEmployed':True}
dictionaryToJson = json.dumps(pythonDictionary)
print(dictionaryToJson)
I'm pretty sure that my python code is not correct. My problem is that how can i write a code in python to send & receive JsonObjects to android with Get or POST method? Thanks.