title: creating json array from arraylist android
body: <p>I've been toying around with this for a little while and I'm looking for some help. I have an <code>ArrayList</code> that I turn into a <code>JSONArray</code> and then place inside <code>JSONObject</code>. The problem is my formatting. Allow me to show you.</p>
  
  <p>I get the values for my <code>ArrayList</code> and add them like so (small code snippet)</p>
  
  <pre><code>if (v instanceof EditText) {
          String answer = ((EditText) v).getText().toString();
          if (answer.equals("")) {
          error.setText(v.getTag().toString()
              + " Needs an answer");
          ((EditText) v).setHint("Fill me out!");
          ((EditText) v).setHintTextColor(getResources()
              .getColor(R.color.red_bg));
          } else {
              error.setText("");
          }
          String question = v.getTag().toString();
          String combo = question + ": " + answer;
          myList.add(combo);
          Log.v("INFO", "Storing: " + combo);
  }
  </code></pre>
  
  <p>This works, but adding the ":" is the start of my problems. The log prints out</p>
  
  <pre><code>06-19 12:13:33.630: V/INFO(3272): Storing: Height: 6`4
  </code></pre>
  
  <p>Now when I create my <code>JSON</code> to be sent over I use the following</p>
  
  <pre><code>if (error.getText().toString().equals("")) {
      JSONObject json = new JSONObject();
      JSONArray jArray = new JSONArray(myList);
      try {
         json.putOpt("array", jArray);
      } catch (JSONException e) {
         e.printStackTrace();
      }
  </code></pre>
  
  <p>Again, this works. Now the problem clearly illustrated, it prints out <code>JSON</code> like this</p>
  
  <pre><code>{
    "array":
    [
      "Store #: 00608",
      "Phone #: null",
      "Address: 3014 N. SCOTTSDALE RD.",
      "City: SCOTTSDALE",
      "Zip: 85251",
      "State: AZ",
      "Height: 6`4",
      "Weight: 230",
      "Ethnicity: White",
      "Age: 23",
      "Eye Color: Blue",
      "Favorite Food: Thai",
      "Comments: awesome"
     ]
  }
  </code></pre>
  
  <p>If you're familiar with <code>JSON</code> you know I've goofed it here. I was merely trying to keep the question and answer together. However by adding the ":" to the middle it looks like I'm trying to use question as the <code>key</code> and answer as the <code>value</code> (kind of). Anyways in the end this looks like legitimate <code>JSON</code>, and it is, but it doesn't work the way I need it to.</p>
  
  <p><strong>My question is, should I just make "question" the <code>key</code>, and "answer" the <code>value</code>?</strong></p>
  
  <p>If so how would I go about creating my <code>JSONArray</code> so that my <code>JSON</code> looks like this</p>
  
  <pre><code>{
    "array":
    [
      "Store #" :  "00608",
      "Phone #" : "null",
      "Address" : "3014 N. SCOTTSDALE RD.",
      "City" : "SCOTTSDALE",
      "Zip" : "85251",
      "State" : "AZ",
      "Height" : "6`4",
      "Weight" : "230",
      ....
     ]
  }
  </code></pre>
  
  <p>So that a simple </p>
  
  <pre><code>var_dump(json_decode($json));
  var_dump(json_decode($json, true));
  </code></pre>
  
  <p>in <code>PHP</code> will provide me with the data I need server side.</p>
  
  <p><strong>or alternatively</strong> would it just be simpler to keep this format and split the strings as I parse them server side? Whichever answer you choose please supply a few lines of code with to illustrate your answer. As you can tell I'm a visual person. </p>
  
  <p>Thanks for the help, I hope this helps other people in the future as well!</p>