Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The string that's causing this error is <strong>the response</strong>, not the request one. Also, with your code <strong>you are not sending a <code>JSONObject</code></strong>, you are just sending 5 different parameters.</p> <p>Let's begin with the request. You cannot send a <code>JSONObject</code> directly to your server, you need to send it as a <code>String</code> and then parse it in the server to get the JSONObject back. The same goes with the response, you will receive a String to parse.</p> <p>So let's create a <code>JSONObject</code> in your client and add it to the parameters list:</p> <pre><code>// Let's build the JSONObject we want to send JSONObject inner_content = new JSONObject(); inner_content .put(CLASSICLevel, "1") .put(CURRENTLevel, "2") .put(UPDATEDate, "345") .put(NAME, "Nil") .put(UPDATETIME, "10"); JSONObject json_content= new JSONObject(); json_content.put("objTimesheet", inner_content); // TO PRINT THE DATA Log.d(TAG, json_content.toString()); // Now let's place it in the list of NameValuePair. // The parameter name is gonna be "json_data" List&lt;NameValuePair&gt; params1 = new ArrayList&lt;NameValuePair&gt;(); params1.add(new BasicNameValuePair("json_data", json_content.toString())); // Start the request function json = jparser.makeHttpRequest(url_login, "POST", params1); </code></pre> <p>Now your server will receive just <strong>ONE parameter called "objTimesheet"</strong> whose content will be a <code>String</code> with the json data. If your server script is <code>PHP</code>, you can get the JSON Object back like this:</p> <pre><code>$json = $_POST['json_data']; $json_replaced = str_replace('\"', '"', $json); $json_decoded = json_decode($json_replaced, true); </code></pre> <p>$json_decoded is an array containing your data. I.e., you can use $json_decoded["Name"].</p> <p>Let's go to the response now. If you want your client to receive a <code>JSONObject</code> you need to send a <strong>valid</strong> string containing a <code>JSONObject</code>, otherwise you get the <code>JSONException</code> you are getting now.</p> <p>The String: "InsertTimesheetItemResult=Inserted successfully" <strong>IS NOT a valid JSON string</strong>. </p> <p>It should be something like: "{"InsertTimesheetItemResult" : "Inserted successfully"}".</p> <p>PHP has the function <strong>json_encode</strong> to encode objects to JSON strings. To return a String like the one I wrote above, you should do something like this:</p> <pre><code>$return_data["InsertTimesheetItemResult"] = "Inserted successfully"; echo json_encode($return_data); </code></pre> <p>I hope this helps you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload