I 'm really new at this. I was working with Java and json.
The question I have is: How I can get the information from my .json file with the following format :
[{"name":"My name","country":"Country name"}]
I can now obtain with the following code:
Json file:
{"name":"My name","country":"Country name"}
Java file:
@Override
protected JSONObject doInBackground(String... args) {
JsonParser jParser = new JsonParser();
JSONObject json;
json = jParser.getJSONFromUrl("http://ift.tt/1KaewyN");
System.out.println("JSON: " + json);
if(json != null) {
try {
name = json.getString("name");
country = json.getString("country");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}
But omitting the [] from my json file ):
How to get the same information without omitting anything of my json file?
I was reading about getJSONArray, and as I see, having my file [] , but I fail to understand well how to work with that file without the array holds "name".
Does anyone understand me? I must not omit [] from my json file .
Sorry for my English ):
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire