Let me start by saying, I'm completely unfamiliar with json parsing. I have json that looks like this,
[
{
"locName":"Kansas"
},
{
"locName":"New York"
},
{
"locName":"Tokyo"
},
{
"locName":"Toronto"
},
{
"locName":"Des Moines"
}
]
I just want to parse the names of the locations into a string list. How do I do it? my code looks like:
while (parser.nextToken() != null) {
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) &&(parser.getText() == 'locName')) {
myList.add(parser.getText());
parser.nextToken();
}
}
serialize
/deserialize
methods of the JSON Class are generally all you will need and simpler to use thanJSONParser
.