Research Development
Research Development

Reputation: 904

how to Parse Map value Data in android

   Map<String, String> map =dataSnapshot.getValue(Map.class);

                String MR_ID = map.get("MR_ID");
                String JOB_TITLE = map.get("JOB_TITLE");
                String JOB_TYPE = map.get("JOB_TYPE");
                String Delv_ADDR=map.get("Delv_ADDR");

DataSnapshot { key = platformdb, value = {MR_RELATIONS={CUSTOMERS={ORDERS={INVENTORY=, Delv_ADDR=D-103 LaxmiNagar New Delhi, ORDER_ID=}}}, MR_SCHEDULE={MR_ID=, JOB_TITLE=, GEO_LINK=, JOB_TYPE={TSP={TSP_ADDR=, TSP_ID=, GEO_LINK=, TSP_NAME=}, SCC={SCC_ID=, SCC_ADDR=, GEO_LINK=, SCC_NAME=}, CUSTOMER={GEO_LINK=, CUST_NAME=, CUST_ID=, CUST_ADDR=}}, JOB_ID=, TRANS_SRC=, TRANS_DEST=}, MR_POOL={FREE_MR=, BUSY_MR={77889992222={IS_BUSY=false, GEO_LINK=8yyttrd}}}} }

This is my Data i am getting in map i want to Parse and and get value of Delv_ADDR But i am unable to get i am getting Null value please suggest me how to get data of that

Upvotes: 1

Views: 534

Answers (1)

ninja.coder
ninja.coder

Reputation: 9658

From the attached input it seems that there is only one entry in the map with key platformdb and value as MR_RELATIONS=....

If you are doing String MR_ID = map.get("MR_ID"); then it will probably return you null as there is no entry in the map with key MR_ID.

What you should be doing instead is retrieve the value against the key by doing the following:

String response = map.get("platformdb");

And then parse this response String to extract the desired values.

Since, response does not seems to be JSON you can try using native String functions.

For example, to extract MR_ID from response you can do the following:

String response = map.get("platformdb");
String MR_ID = response.substring(response.indexOf("MR_ID=") + 6,
                                  response.indexOf("MR_ID=") + response.indexOf(","));
String Delv_ADDR = response.substring(response.indexOf("Delv_ADDR=") + 10,
                                  response.indexOf("Delv_ADDR=") + response.indexOf(","));

Upvotes: 1

Related Questions