how to check that json string is valid or not? - android

Is it possible to check whether json string is valid or not? The string is as follows which I want to check
{
"bakso-roso-n'deso__-6.19_106.77":
{"Latitude":"-6.185488","Longitude":"106.77366","Distance":"90.89210930799594"},
"print-point-duri-kepa__-6.19_106.77":
{"Latitude":"-6.18599544813468","Longitude":"106.77267676603988647","Distance":"118.9849339548274"},
"apartment-menara-kebun-jeruk__-6.19_106.78":
{"Latitude":"-6.185303767096767007","Longitude":"106.7752222767679179","Distance":"247.8816947606767"},
"ranch-market---pesanggrahan__-6.19_106.77":
{"Latitude":"-6.1876130647tg7t72002","Longitude":"106.77343661177","Distance":"294.4255786871916"}
}

you can use the link http://jsonlint.com/

I use http://jsonlint.com/ to validate my json

I have got a better online json parser. It even tells at which point json is wrong. and tells at which point what thing is missing.
you need not click on validate. it automatically checks error at runtime. it's really cool. try it :)
http://json.parser.online.fr/

Related

analyze JsonObject from Facebook Graph API Error

I had error
org.json.JSONException: No value for data
image
I had tried many ways but I can't solve it. Please help me to fix it.
It is possible to use Gson API to parse JsonObject above to java Object?
You need to get posts before.
JSONArray data = responde.getJSONObject("posts").getJSONArray("data");
instead of
JSONArray data = responde.getJSONObject().getJSONArray("data");
This should work for this scenario, but you really need to check for non existent keys or values.

Parse xml Data from FormBuilder

I get the following response for FormBuilder. I want parse it.
How to parse it??
<LoactionApi><Status>OK</Status><ReportURL/><
Locations>
<Location><name>jack</name><number>357-151-04-00</number><Address>Ahmedabad</Address><City>Ahmedabad</City><State>Gujarat</State><ZIP>380007</ZIP><ZIP4>6518</ZIP4><UnitType/><UnitNumber/>
<MatchStatus>No Exact Match</MatchStatus>
<StatusCode>NM</StatusCode>
</LoactionApi>
Thanks
Please check your XML response that you have shown over here. It is not at all valid !!!
For checking that your xml is valid. Validate it over here
http://www.xmlvalidation.com/
Show me the correct xml. I will help you

output text line by line

I write app for Android such gets data from server in JSON format. Now I get this value in string, but in my application it must look like:
Route:
1)first point
2)secon point
3).....
n) n point
I read that in Android in textView I can do it if string will be with html tags but I think it is not the best variant. After Android I must do it in iPhone now I don't know how to do that there. Send Routes as Array is not good variant too. Can you say what is the best way to decide this problem?
Have a look here you will have to find the good pattern .
Hence you have separated strings just use a list View with an ArrayAdapter.
I am not so good with regex but i think it should like : [1-9][0-9]) [[a-f][0-9]]+
I couldn't comment b/c of rep, sorry. Could you provide an example of returned JSON string. I think JSON format can be parsed with ease.
If this the case you can parse it in a loop (or another way. I'm not that good at it)
String[] parseIt (String JSON){
String[] list=JSON.split("\\d\\)");
String[] rlist=new String[list.length-1];
for(int i=0;i<list.length-1;i++){
rlist[i]=list[i+1].trim();
}
return rlist;
}
This might do trick. But you should edit result. I didn't test yet
Edit: I edited code. It simply return the address now with leading whitespace. You can get rid off them using. String trim() method like;
list[1].trim();
Do it in loop and don't care about first element (index 0).
Edit 2: Now it should work

android - simple way to extract a key-value pair from a json string?

Suppose I have a json string like this:
{ ... "key1":"value1"; ... }
with a key1-value1 pair somewhere deep down the json structure (which includes other things such as array, dictionary, etc...). I don't know exactly (and don't care) how the exact structure of the json is.
Is there a simple way to extract the "value1" ? (if there are 2 "key1" in the json string then I just need the first one).
As far as I know, you have no chance of doing it manually.
If you really don't know what's the structure of the JSON string you're expecting, you can try a graph search approach, such as DFS (http://en.wikipedia.org/wiki/Depth-first_search).
For every key, check if it is an array.
If so, go inside and repeat the procedure. If nothing was found in a given array, backtrack.
Interrupt your process once you have found your key.

JSON Parser Android

JSONObject jObject = new JSONObject(myJsonContent);
JSONObject menuObject = jObject.getJSONObject(String.valueOf(jObject.keys().next()));
myJsonContent is response from server
and i dont know what is start tag ... and i dont want to know even...
and after that without knowing any tag of response i want to parse response..
this is requirment because in the future we will not be knowing if server guys change data and tags as well so we need to create like this which will be work even if server guys changes all the tags in future
please help me any kind of help is very appriciable
You should check here,
http://developer.android.com/reference/org/json/JSONObject.html
get keys from json object i.e. iterator and loop thorough it and use jsonObject.names() to get the array of names. This should guide you to the right solution.
Sorry for the plug, but you could try do what I did - use this parsing object generator

Categories

Resources