php - I get duplicate error when I post same string using NameValuePair


I am posting strings to server using Http post, when I post a single string using NameValuePair it works perfectly but when I repeat the same strings I get error of duplicate strings, and does not upload to server. I need any that can accept duplicate strings and its equivalent JSONParser.

    List<NameValuePair>params = new ArrayList<NameValuePair>();
                params.add(new BasicNameValuePair("message", "me"));

This is the error I get when I try to post same string again:

Error parsing data org.json.JSONException: Value Duplicate of type java.lang.String cannot be converted to JSONObject




The JSON standard doesn't allow to have two entries with the same name. May u want to use an array instead?

Think what you want to do is something like that:

$json = json_encode(
      1 => array(

So its

"1": ["one","two"]

instead of


Or do you mean on the Android site? I can recomment to use JSON-Simple, thats light & easy. Example:

      //import org.json.simple.JSONObject;
      //import org.json.simple.JSONArray;

      JSONObject obj=new JSONObject();
      JSONArray list = new JSONArray();
      list.add(new Integer(100));
      list.add(new Double(1000.21));
      list.add(new Boolean(true));
      obj.put("foo", list);

Result: {"foo": ["foo",100,1000.21,true,null]}

People are also looking for solutions to the problem: php - Auto fill input boxes with data from JSON in CodeIgniter


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.