2

Edited:

Hello guys, I want some help please. I actually want to get and use some useful data from a url. I have a website that displays the info about some major accidents in a specific area. I want to get the the details of those accidents from that website. I will display them in Android-MapView with pin-points. How can I do this? I have suffered through it but still unable to do this.

user2281330
  • 181
  • 2
  • 11

3 Answers3

2

you can do the following thing using json

1>first encode the data you want to receive in json format at url from where you want your data.

2>now request for encoded json data from android app.

3>based on your encoding the url will return jsonArray or jsonObject

4>extract the data your want from your reeceived json array or json object and use it as you want...

search SO for how to encode and use json...hope this helps

karan
  • 8,637
  • 3
  • 41
  • 78
  • CHECK this link...http://stackoverflow.com/questions/16490151/error-parsing-json-data-value-of-type-java-lang-string-cannot-be-converted-to-j – karan Jun 04 '13 at 17:06
0

First, make sure <uses-permission android:name="android.permission.INTERNET" /> is in your AndroidManifest.xml.

I don't see why something like this wouldn't work.

URLConnection connect = someUrl.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(connect.getInputStream()));

ArrayList<String> inputLine = new ArrayList<String>();
String tempString;

while ((tempString = in.readLine()) != null) {
    inputLine.add(tempString);
}
in.close();

for (String s : inputLine) {
    // do stuff
}

The // do stuff could be something using String.substring or String.replace in conjunction with String.startsWith, or whatever else you want to use to parse the HTML.

You will need to add in exception catching, I could be wrong but I think the only exceptions you have to worry about here is IOException.

DenWav
  • 53
  • 1
  • 11
0

You can use some library to help you with the parsing. For example jsoup or something from here. I have never worked with any of these myself though, so I can't really help you in any other way than pointing you to them. But I am sure that at least some of them will have nice tutorials and/or documentation.

zbr
  • 6,860
  • 4
  • 31
  • 43