I don't know much about JSON parseing. The JSON API is like that.
[
"Text A" , "Text B" , "Text C"
]
I want to get all the texts from api directly from server.
How can I get these texts (Text A ,Text B , Text C) as an array?
I don't know much about JSON parseing. The JSON API is like that.
[
"Text A" , "Text B" , "Text C"
]
I want to get all the texts from api directly from server.
How can I get these texts (Text A ,Text B , Text C) as an array?
Its a simple basic jsonarray...you need to take jsonarray object and store the whole jsonarray then you need to iterate jsonarray indexes and save the string to string array
JSONArray mainjson=new JSONArray(<jsonstring>);
String text[]=new String[mainjson.length()];
for(int i=0;i<mainjson.length();i++)
{
text[i]=mainjson.getString(i);
}
Using AQuery Library You can Do it Simply Like this, First Download Aquery.jar File & Paste it in your Lib Folder of Project.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AQuery aq = new AQuery(this);
String url = "YOUR URL HERE";
aq.ajax(url, JSONArray.class, this,
"jsoncallback");
}
public void jsoncallback(String url, JSONArray jsonArray, AjaxStatus status) {
String[] values; // this array will store your Strings
if (jsonArray != null)
{
try {
for (int i = 0; i < jsonArray.length(); i++)
{
value[i] = jsonArray.getString(i);
}
}
catch (JSONException e)
{ // TODO Auto-generated catch block
e.printStackTrace();
}
}
else
{
// Json is Null
}
}