-1

i create a array in my php file

$array = array();

and give it value and encode it by json like this :

`json_encode($array)`;

this is my output :

[
 "1",
 "notification 1",
 "hello",
 "first notification",
 "2015-07-23",
 "2015-07-30",
 "www.google.com",
 "2",
 "notification 2",
 "hello2",
 "second notification",
 "2015-07-23",
 "2015-07-28",
 "www.yahoo.com"
]

how can i parse it in android

i want a array in android

plz help me

asked Jul 26, 2015 at 14:51
4
  • I don't understand your question. Commented Jul 26, 2015 at 14:57
  • First, that looks more like a standard array (list) more then a json array. Second, your question is difficult to understand as it stands - please add your code and read the help for creating a question as this will help other to help you. Commented Jul 26, 2015 at 14:57
  • i add some details i hope this one be correct question Commented Jul 26, 2015 at 15:17
  • Also agree that you aren't really using JSON properly for what I expect your desired outcome is. To parse it (or a proper JSON array), you can look into the json.org libraries, or any other Java JSON library Commented Jul 26, 2015 at 15:21

3 Answers 3

0

Here is how to transform your Json Array String into a Java ArrayList :

String json = "['1','notification 1','hello','first notification','2015-07-23','2015-07-30','www.google.com','2','notification 2','hello2','second notification','2015-07-23','2015-07-28','www.yahoo.com']";
JSONArray jArray = json.getJSONArray(json);
ArrayList<String> = new ArrayList<String>(jArray.length());
for (int i = 0; i < jArray.length(); i++) {
 arrayList.add(jArray.getString(i));
}
answered Jul 26, 2015 at 15:26
Sign up to request clarification or add additional context in comments.

Comments

0
String jsonResult = inputStreamToString(response.getEntity().getContent()).toString();
JSONArray mArray = new JSONArray(jsonResult);
for (int i = 0; i < mArray.length(); i++) {
JSONObject object = mArray.getJSONObject(i);
String name = object.getString("name");
String password = object.getString("password");
String link= object.getString("link");
String dateFrom= object.getString("dateFrom");
String dateTo= object.getString("dateTo");
textView.setText(name + " - " + password);

}

You can use this code , adapt it for your need.

answered Jul 26, 2015 at 15:21

Comments

0

Can you please try below solution ?

String result = "[
 "1",
 "notification 1",
 "hello",
 "first notification",
 "2015-07-23",
 "2015-07-30",
 "www.google.com",
 "2",
 "notification 2",
 "hello2",
 "second notification",
 "2015-07-23",
 "2015-07-28",
 "www.yahoo.com"
]"

Now fetch each element by below code:

String [] array = result.split(",");
 for (int i=0; i<array.length;i++){
 Log.i("Element @ "+i, array[i]);
 }

Hope it will help you.

answered Jul 26, 2015 at 15:53

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.