****I Want to pass this JSON String to URL Parameters so the Web Server Can read and save the Values in Database.**
"data": [{
"Id": "000039",
"Name": "6502418"
}, {//Json Array
"Id": "000037",
"Name": "6502418"
}, {
"Id": "000039",
"Name": "6502418"
}]//Json array
Here is my Full Code Of how to Make this String In Android Application.
try {
ds = new DataSource(cont);
final URL url = new URL("http://asd.mo:1980/MOB/SendDoc.aspx");
con = (HttpURLConnection) url.openConnection();
Log.v("jarvis","Connection Check"+ con);
con.setDoInput(true);
con.setDoInput(true);
con.setChunkedStreamingMode(0);
con.addRequestProperty("Content-Type","application/json;charset=utf-8");
con.setRequestMethod("POST");
ds.open();
Cursor cursor = ds.send(); //cursor hold all your data
JSONObject jobj ;
JSONArray arr = new JSONArray();
cursor.moveToFirst();
while(cursor.moveToNext()) {
jobj = new JSONObject();
jobj.put("Id",cursor.getString(cursor.getColumnIndex(DatabaseHelper.COL_DA_DOC_ID)));
jobj.put("Name", cursor.getString(cursor.getColumnIndex(DatabaseHelper.COL_DA_EMP_ID)));
arr.put(jobj);
}
jobj = new JSONObject();
jobj.put("data", arr);
String st = jobj.toString();
OutputStream out = new BufferedOutputStream(con.getOutputStream());
out.write(st.toString().getBytes());
Log.v("jarvis","Json string" + st.toString()); //from here I grab my JSON Array i want to throw this in URL as paramaters
out.flush();
out.close();
ds.close();
int result =con.getResponseCode();
Log.v("jarvis","ResponceCode = " + result);// Show me 500.
if (result==200){
InputStream in = new BufferedInputStream(con.getInputStream());
reader = new BufferedReader(new InputStreamReader(in));
StringBuilder sb = new StringBuilder();
String line= null;
while ((line = reader.readLine()) != null){
Status=line;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return Status;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
if (result != null){
Toast.makeText(cont,"Data Save SuccessFully",Toast.LENGTH_LONG).show();
}else{
Toast.makeText(cont,"Data didnot Save.Please Check Connection",Toast.LENGTH_LONG).show();
}
}
It also give me response Code 500 Can anyone please tell me how I am getting all the values in Param?**
You can use my class:
You can run this from your Activity:
}`
here is my Web Server Code.