1

This is how I post the values with Volley:

@Override protected Map<String, String> getParams() { JSONObject jsonObjectMembers=new JSONObject(); for (int i=0; i<arr_added_userids.size(); i++) { try { jsonObjectMembers.put("params_"+i,arr_added_userids.get(i)); } catch (JSONException e) { e.printStackTrace(); } } Map<String, String> params = new HashMap<String, String>(); params.put("host", session_userid); params.put("params",jsonObjectMembers.toString()); return params; } 

This is what I tried:

foreach($_POST['params'] as $key => $value) { try { $stmt = $conn->prepare("INSERT INTO CREWMEMBERS (CREWID, MEMBER) VALUES (:crewid, :member)"); $query_params = array( ':crewid' => $crewid, ':member' => $value ); $stmt->execute($query_params); $response["success"] = 1; } catch(PDOException $e) { //echo 'ERROR: ' . $e->getMessage(); $response["success"] = 3; } } 

I always get org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject

When I send $_POST['params'] to myself in email to see how it looks like, I get

{"params_0":"000000000284","params_1":"000000000229","params_2":"000000000081"} 

How do I handle these items separately?

2
  • ' always get org.json.JSONException: Value <b'. Where? I see no code that would produce such an error. Commented Apr 5, 2015 at 20:02
  • Which org.json jar are you using? There seem to be several around with that name. Also how can the PHP code (at least in the way you ask this question) throw a Java exception? Commented Apr 6, 2015 at 2:14

2 Answers 2

1

I have just faced the same problem. My solution:

Map<String, String> params = new HashMap<String, String>(); params.put("params[0]", "a"); params.put("params[1]", "b"); params.put("params[2]", "c"); 
Sign up to request clarification or add additional context in comments.

1 Comment

I don't think this would help. I solved this long ago but what the code is missing now is the parameters from the getParams() part.
0
Map<String, String> params = new HashMap<String, String>(); params.put("params[0]", "a"); params.put("params[1]", "b"); params.put("params[2]", "c"); 

1 Comment

Could you provide a little more information in this answer for reference. Maybe why this way is the best option, what is it doing differently from the op that fixes the issue?.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.