Doraemon 24 Doraemon 24 - 1 year ago 76
JSON Question

Android.Filtering using if statement getting data from JSON

I am reading all data from a

file but I want to filter out all "Delivered" delivery_status. So I use
if(status == jobj.getString(DELIVERY_STATUS))
. BUT NOTHING WORKS. please help me

The output MUST BE only:

{"delivery_id":"4","client_firstname":"Marie",delivery_status":"On the Road"} (Code Snippet)

public static final String DELIVERY_ID = "delivery_id";
public static final String CLIENT_FIRSTNAME = "client_firstname";
public static final String DELIVERY_STATUS = "delivery_status";

JSONArray ja = response.getJSONArray("delivery");

for (int i = 0; i < ja.length(); i++) {
JSONObject jobj = ja.getJSONObject(i);
HashMap<String, String> item = new HashMap<String, String>();
String status = "Delivered";

if(status == jobj.getString(DELIVERY_STATUS)) {
item.put(DELIVERY_ID, jobj.getString(DELIVERY_ID));
item.put(DELIVERY_STATUS, jobj.getString(DELIVERY_STATUS));

} // for loop e

.json file

{"delivery_id":"4","client_firstname":"Marie",delivery_status":"On the Road"}]

Answer Source

For this you have to do like this,


      //your code
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download