This question already has answers here:
How do I parse JSON in Android? [duplicate]
(3 answers)
Closed 5 years ago.
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.
Your response looks like JSON,
so for json response in result;
JSONObject lsubObject= new JSONObject(result);
String MaCID =lsubObject.getString("MaCID");
This question already has answers here:
How to parse JSON in Java
(36 answers)
Closed 5 years ago.
This is my JSON data format
[{"member":[{"id":"1","name":"A V S Murthy (Sanjeev)","mobile1":"9845072215","mail_id":"alampalli.murthy#gmail.com","bg":"O +Ve"},{"id":"67","name":"Sundaramurthy N C","mobile1":"9845026300\t","mail_id":"ncsmurthy1943#gmail.com","bg":"O +Ve"}]},{"anne":[{"id":"1","name":"A V S Murthy (Sanjeev)","mobile1":"9845072215","mail_id":"alampalli.murthy#gmail.com","bg":"O +Ve","anne_name":"Shoba A Murthy","anne_mobile":"","anne_email":""}]},{"annets":[]}]
First visit to http://www.jsonschema2pojo.org/ and create your model classes. (or create manually)
Than use to https://github.com/google/gson library for parsing
This question already has answers here:
Simple parse JSON from URL on Android and display in listview
(6 answers)
parse simple json string in android
(4 answers)
Closed 7 years ago.
i have a url that inide of this url is json code .
i need this content to decode. for example if my url is : http://url.com
i have this json in it:
{ "employee":{"mesg":"username is exsist!","id":0,"name":0,"username":0,"email":0,"status":500} }
i need from url.com this data to put in a variable and decode this.
for decoding i dont have problem . just i need to get data from url , like file_get_contents in php .
, thanks
NOTICE:
i use HttpClient for this solution . but it is deprecated . is another way for this?
You can use IOUtils.toString(url) from Apache Commons library.
This question already has answers here:
How do I parse JSON in Android? [duplicate]
(3 answers)
Closed 7 years ago.
In my project, I am getting the following JSON from the HTTP response.
{"base":"USD","date":"2015-04-24","rates":{"AUD":1.2827,"BGN":1.8069,"BRL":2.9733,"CAD":1.2119,"CHF":0.9551,"CNY":6.1948,"CZK":25.364,"DKK":6.8927,"GBP":0.6614,"HKD":7.75,"HRK":7.0284,"HUF":278.53,"IDR":12954.0,"ILS":3.9244,"INR":63.563,"JPY":119.51,"KRW":1078.25,"MXN":15.358,"MYR":3.5741,"NOK":7.8298,"NZD":1.3216,"PHP":44.281,"PLN":3.7076,"RON":4.08,"RUB":51.215,"SEK":8.6674,"SGD":1.3375,"THB":32.55,"TRY":2.7314,"ZAR":12.182,"EUR":0.9239}}
I want to get the "BGN" from the above json. How to get it.
There are multiple steps involved in this
First: Create a jsonObject
JSONObject jObject = new JSONObject(yourJSON_String);
Second: Get your desired Object or Array, in your case
obj = getJSONObject("rates")
Third: Get required String
obj.getString("BGN");
Here is the JSON CLASS REFERENCE
Assuming you are using JSONObject, and that your root document is called "doc",
JSONObject rates = doc.getJSONObject("rates") would get you the rates part:
{"AUD":1.2827,"BGN":1.8069,"BRL":2.9733,"CAD":1.2119,"CHF":0.9551,"CNY":6.1948,"CZK":25.364,"DKK":6.8927,"GBP":0.6614,"HKD":7.75,"HRK":7.0284,"HUF":278.53,"IDR":12954.0,"ILS":3.9244,"INR":63.563,"JPY":119.51,"KRW":1078.25,"MXN":15.358,"MYR":3.5741,"NOK":7.8298,"NZD":1.3216,"PHP":44.281,"PLN":3.7076,"RON":4.08,"RUB":51.215,"SEK":8.6674,"SGD":1.3375,"THB":32.55,"TRY":2.7314,"ZAR":12.182,"EUR":0.9239}
From this object you can then simply get the BGN value using
String bgn = rates.getString("BGN")
JSONObject responseJson = new JSONObject("<your-string">);
JSONObject ratesJson = responseJson.getJSONObject("rates");
double rate = ratesJson.getDouble("BGN");
To see the JSON object clearly, use PrettyJson. Copy paste the JSON string here and it will show you nested objects (if any) for clearly understanding the response.
This question already has answers here:
Parsing JSON file in android
(4 answers)
Closed 7 months ago.
I need to call this URL: https://login.skype.com/json/validator?new_username=name.surname
I obtain a json file format. I need only to take the element associated to tag "status". For the above link is "status":406, so I need the value 406. What is the most simple way for implementing a parser that get only this element?
Simplest way to do it for this particular situation is
JSONObject obj=new JSONObject(myJSONString);
String status=obj.getString("status");
You'll have to handle the JSONException incase the tag "status" isn't found.
Have you got this response as a string yet? That is your first step but as you are asking for a parser I assume youve done this. If so the rest is easy:
String jsonString = parsedString; //The downloaded JSON String
JSONObject firstObj = new JSONObject(parsedString);
String status = firstObj.getString("status");