-5

I have following String response. Out of which I want to extract MAC ID & other fields like Version, Type, devIP etc.

Response ={ 
"Version" : “1.10", 
"Type" :"'xyzTYPE", 
"MaCID" :"ABCD1F2G3900", 
"devIP" : "'192.168.1.100", 
"Signal": "-66", 
"AreaName" :"'power", 
"SubType" :"wifidev", 
"'BuiIdTime" : "11:50:47", 
"'BuiIdDate": "'Nov 2 2018" 
}

Though I have implemented it in this way.

String macID = result.substring(result.indexOf("MaCID")+11,result.indexOf("devIP")-4);

I want to know if there is another sophisticated manner to do the same.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

1 Answers1

1

Your response looks like JSON, so for json response in result;

 JSONObject lsubObject= new JSONObject(result);
    String MaCID =lsubObject.getString("MaCID");
Kapil Parmar
  • 881
  • 8
  • 19