Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.devstream.http;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- import android.app.Activity;
- import android.os.Bundle;
- import android.util.Log;
- public class MainActivity extends Activity {
- private static final String TAG = "MainActivity";
- private static final String URL = "http://10.0.2.2:8081/openmrs-standalone/ws/rest/v1/muzima/queueData";
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- // JSON object to hold the information, which is sent to the server
- JSONObject jsonObjSend = new JSONObject();
- try {
- // Add key/value pairs
- jsonObjSend.put("datasource", "3c023ab8-82ff-11e2-96ef-f0def12f7061");
- jsonObjSend.put("discriminator", "encounter");
- // Add a nested JSONObject (e.g. for header information)
- JSONObject payload = new JSONObject();
- JSONObject encounter= new JSONObject();
- JSONObject person= new JSONObject();
- JSONArray obs=new JSONArray();
- JSONObject o = new JSONObject();
- payload.put("person",person); // Device type
- payload.put("encounter",encounter);
- payload.put("obs",obs);
- obs.put(o);
- person.put("person.uuid","269857b6-f0b9-4c93-af4a-f18293679e89");
- encounter.put("form.uuid","fe9fc58f-d196-46cb-956d-f46445f558d9");
- encounter.put("encounterType.uuid","bdb58960-4d91-4ca7-a27a-8dabde40ec12");
- encounter.put("provider.uuid","3c023ab8-82ff-11e2-96ef-f0def12f7061");
- encounter.put("location.uuid","e1b1d9eb-69a2-4843-bccc-e73e33c70e4c");
- encounter.put("datetime","2013-06-17 00:00:00");
- o.put("uuid", "307AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
- o.put("type", "coded");
- o.put("value","1364AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
- // Device OS version
- //header.put("language", "es-es"); // Language of the Android client
- jsonObjSend.put("payload", payload);
- //Output the JSON object we're sending to Logcat:
- Log.i(TAG, jsonObjSend.toString(2));
- } catch (JSONException e) {
- e.printStackTrace();
- }
- // Send the HttpPostRequest and receive a JSONObject in return
- JSONObject jsonObjRecv = HttpClient.SendHttpPost(URL, jsonObjSend);
- /*
- * From here on do whatever you want with your JSONObject, e.g.
- * 1) Get the value for a key: jsonObjRecv.get("key");
- * 2) Get a nested JSONObject: jsonObjRecv.getJSONObject("key")
- * 3) Get a nested JSONArray: jsonObjRecv.getJSONArray("key")
- */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment