parsing html data in android - android

I am making an application in which i have to parse HTML data. I have got data that i want. But data is repeating five to six times. I m saving data into string, but when i am printing this string there is no repeated data. e.g data having 23 values and it is repeating five or six times. I have entered static string it is displaying fine.
Here is code:
doc = (Document) Jsoup.connect("http://altoona.craigslist.org/search/cta?query=Ford+WINDSTAR&srchType=T&minAsk=&maxAsk=").get();
System.out.println("*****DOC*****"+doc);
s1=doc.getAllElements().text().toString();
System.out.println("**************S1*************"+s1);
Please help me where m doing something wrong.

try this one http://htmlparser.sourceforge.net/
HTML Parser is a Java library used to parse HTML in either a linear or nested fashion. Primarily used for transformation or extraction, it features filters, visitors, custom tags and easy to use JavaBeans. It is a fast, robust and well tested package.

Related

How to add the data from an api without Pojo

I am getting data from an api which cannot be converted into pojo so am not able to get the data in a normal manner
Data that i am getting
{"TABLE_DATA":"
{\"data\":[
[\"Tiger Nixon\",\"System
Architect\",\"Edinburgh\",\"5421\",\"2011/04/25\",\"$320,800\"],
[\"Garrett
Winters\",\"Accountant\",\"Tokyo\",\"8422\",\"2011/07/25\",\"$170,750\"],
[\"Ashton Cox\",\"Junior Technical
Author\",\"SanFrancisco\",\"1562\",\"2009/01/12\",\"$86,000\"],
[\"Cedric Kelly\",\"Senior Javascript
Developer\",\"Edinburgh\",\"6224\",\"2012/03/29\",\"$433,060\"],
[\"Airi
Satou\",\"Accountant\",\"Tokyo\",\"5407\",\"2008/11/28\",\"$162,700\"],
[\"Brielle Williamson\",\"Integration Specialist\",\"New
York\",\"4804\",\"2012/12/02\",\"$372,000\"],
[\"Herrod Chandler\",\"Sales Assistant\",\"San
Francisco\",\"9608\",\"2012/08/06\",\"$137,500\"],
[\"Rhona Davidson\",\"Integration
Specialist\",\"Tokyo\",\"6200\",\"2010/10/14\",\"$327,900\"],
[\"Colleen Hurst\",\"Javascript Developer\",\"San
Francisco\",\"2360\",\"2009/09/15\",\"$205,500\"],
[\"Sonya Frost\",\"Software
Engineer\",\"Edinburgh\",\"1667\",\"2008/12/13\",\"$103,600\"],
[\"Jena Gaines\",\"Office
Manager\",\"London\",\"3814\",\"2008/12/19\",\"$90,560\"]`
there is no pojo available This is my first time working in an API any guide will be helpful. I am receiving the following data using retofit and rxjava2.
Data format is post method .
This is a jquery format. You may try to use this https://javacodegeeks.com/2013/02/jquery-datatables-and-java-integration.html
Look also this topic stackoverflow.com/questions/48942253/how-to-implement-jquery-datatable-in-android-any-library
The service you get data from may have an opportunity to set data format, you must specify it in your GET query, look in the API documentation.
That looks a lot like a .csv file. CSV files were the old format of Comma Separated Values, built from Tabular data.
Each row is one object and each column is its attribute/field. You can read about CSV files here.
Approach 1
Filter out using string manipulation the extra symbols of slashes and quotes. Delimit at the square braces (more info here) and then reading each delimited comma separated value text by any CSV reading library. Here's a tutorial using Apache Commons CSV library to read CSV files in Java.
Approach 2
Instead of using any library, if your response set is small and you don't need as much parsing optimization, write your object class's constructor to take in each row, filter out the useless symbols (using string manipulation) and initialize your object's fields.
All steps involved:
Clean response and remove unnecessary symbols using string manipulation.
Build a POJO class to keep one row of the dataset. Have its constructor to take in the first row of your dataset to initialize its attributes.
Build a list format or ArrayList format of your previous class with additional methods to sort, search or call by indices as required.
Build a constructor for this list object class to read in your cleaned string response and iterate over it to build Employee objects and adding them to your list.

Android Parse a JSON String With Quotes in Keys and Values

Android JSON parsing is rather straightforward until it comes to have json reserved characters in your keys/values. I have JSON coming from an HTTP socket whose response is put into a string variable. It looks like this
{"ZboAdtPw4bA":"Ben Heck"s PlayStation 4 Slim Teardown","iC4qIx72_Cc":"Ben Heck's Xbox Slim Teardown"}
See the double quotation in the first value? It even screws up on StackOverflows web page. How am I supposed to escape/prevent this from happening? If I do a:
response = response.replace("\"", "");
Then all the double quotation get replaced, not just the ones in the key/value pair. This is because its all contained in one string at the moment. I am wondering if there is an easy way to do this with android. And of course, java answers are acceptable to. Now I could do this since its just a single dimensional key/value pair easily, I may not even need JSON, but I would like to adhere to standards.
you are simply trying to ruin the basic of a JSON .
you simply add
"/"" to the java code .
other than that its not possible for the parser to differentiate between the quotations from the JSON format or the quotations in the string .

How would I go about displaying data from an API website and putting it in text format on an activity page?

I want to show data in a sensible form for my movie database app. The website I am using to extract data from is www.omdbapi.com. I have already created a code that extracts the title and year of the movies and displays it in a ListView form which contains items that are all clickable to another activity. I would like each activity that the ListView item clicks to to display the movie information under different headers etc.
I have been stuck on this issue all day. I'm new to coding and have no clue what most processes are called etc. Im not asking for the entire code, just instructions on what to do because I am stumped. I would be very very grateful.
Thank you.
Depending on the format the response is formatted you would either use (probably) an xml parser or a JSON parser and grab the info between specific xml tags or the specific keys within the JSON output.
There are thousands of examples of both methods. If you can get the title to display, then you already know how to get the other elements.

Converting multiple datas into a single string for uploading using json in android

I have to submit data from 30 pages into the server.These datas from 30 pages are to be made into a single string and that i have to upload that single string into the server using json.
Each page may contain many answers tht may be either in plain text(value we receive from edit text),from check boxes(yes or no) and so on.....please suggest me a way to add all these data into a single string and upload it using json.
Based on the comment I suspect that you believe that you need to treat these "pages" as strings that you concat. However, what I think you're overlooking is that JSON is pretty versatile in how you add objects to it.
So, let's say you have the thing that you want to ship to your server and you call it
JSONObject myEntireFile = new JSONObject();
you can now add stuff to it at any time like this...
JSONObject page1 = new JSONObject();
myEntireFile.put("page1", page1);
meanwhile you can put whatever you want IN page 1 (cause that's just another serialized container).
You can keep doing this until you're ready to send it, at which time you just call
myEntireFile.toString();
which will convert your object into one long, well formatted, JSON string, that you can then open store for later use.

how to extract web text in android like rss to display it on android GUI?

how to extract some criteria from this page http://www.zigwheels.com/api/zigtvApi.php?method=data&module=News&section=News
and filter this ( content_id , thumbnail, summary , headline , image) to display them as rss feeds in my android GUI
The output from that URL looks like a JSON feed. You can easily parse JSON data in Android using the JsonObject - see this tutorial for a comprehensive example.
A better (and probably easier) solution would be to use Google Gson and extract the object that way. I've written a full (compilable) program you can use as an example here.
You are receiving a JSONArray from that page. You should create some objects from that JSONArray which will be later displayed in a ListView. For retrieving objects from that feed you could use Json or Gson as #Marvin Pinto suggested, or you could also have a look at my ObjectFactory project, which is a very simple and easy to use parser. It can simply create your objects from a json or xml feed, and you could also use it asynchronously.
After you fetch your objects, with your desired option, you can create a ListAdapter and use it to display your objects in your ListView.

Categories

Resources