2

Consider this JSON string:

{
          "title": "value1",
          "link": "value2",
    "media:info": "value3"
}

I know how to parse title and link, but the parser isn't accepting media info because of the colon in the middle I think. Does anyone have any ideas?

Praful Bhatnagar
  • 7,425
  • 2
  • 36
  • 44
user1028408
  • 1,220
  • 3
  • 15
  • 17

1 Answers1

1

Use JSONObject. I wrote the following tests using your example data and they passed.

public void testJsonParsing() throws JSONException {
    JSONObject manual = new JSONObject();
    manual.put("media:info", "value3");

    String rawData = "{ \"title\": \"value1\", \"link\": \"value2\", \"media:info\": \"value3\" }";
    JSONObject parsed = new JSONObject(rawData);

    String expected = "value3";
    String actual = manual.getString("media:info");
    assertEquals("Actual equals expected", expected, actual);

    actual = parsed.getString("media:info");        
    assertEquals("Actual equals expected", expected, actual);
}
Rich
  • 36,270
  • 31
  • 115
  • 154
  • Hi, I didn't notice that this question was posted, I thought it failed, please refer to this question instead: http://stackoverflow.com/questions/13462076/how-do-you-parse-json-with-a-colon-in-the-name-android-java – user1028408 Nov 20 '12 at 06:32