Android PList problem with XMLwise: Object/String to List View - android

I'm hoping this hasn't been repeated before but I've been stuck on this for about an hour now.
I'm using the XMLwise library to parse a remote PList on an Android app. This parsed data returns a Map. The first item in this Map is the data I want, which when logged gives me this when I use getValue() on the Map entry:
[
{
description=Teaching at the University of Kent has been ranked among the best in the UK by the Guardian 2012 University Guide.,
url=http://www.kent.ac.uk/news/homepagestories/university-of-kent-teaching-ranked-among-best-in-uk/2011,
title=University of Kent teaching ranked among best in UK} .....
},
// etc
]
Now I'm fairly new to Android bu that looks like an array of objects to me, from what I know from JSON notation. Java is telling me this is an Object, so I can't seem to parse this or loop through it. I'm wondering if anyone know what the best way to go about parsing this an attaching it to a ListView would be.
As a note, I've tried several different methods of parsing the Plist data and this library is first one that worked so I'm really not interested in other ways to be honest, just hoping to find out how to parse the data I've received.
Thanks very much!

You will need to cast the Object to be an ArrayList<Object> to iterate over it, based on my reading of the source code.

Related

Displaying raw JSON in a user friendly way

I am trying to create a raw JSON viewer for JSON strings. I understand there are apps that already do this but I am looking to load JSON from my server and display it for an internal tool for my company.
I am able to pretty print the JSON values, but this can still be difficult to read. Are there any Android libraries available for displaying color-coded JSON or JSON that can have its items expanded? If not can anyone suggest a way to do so? I've looked into ExpandableListView but this only goes up to two levels deep
Recommend you to see GSON, it simplify JSON.

JSON and a .rss file

I'm pretty new to android development and I was wondering if I could get some input on what to do in my case. I'm trying to make a list of events that are going on at my school using the calendar that's on its website. The problem is, the only way I found to get to the JSON format is through the .rss which looks like this link
I put it into myjson and got this error message and I have no idea what it means:
Parse error on line 1:
My goal is to be able to use JSON to create a list in a ListView on the app I'm making, but so far I'm completely lost as far as what to do. Any help is appreciated!
JSON is entirely different from RSS.
Look into this tutorial here or check out github, there's a ton of libraries that support RSS parsing such as this or this

Parsing "ANY" object from/to JSON in *native* Android

I've read dozens of post (here and other places) asking for parsing from/to JSON and most people code their exclusive parsers for each class. The usual answer is to use GSON or other libraries but since android supports JSON natively I don't see the point of use third-party libraries.
So I made my own generic JSONParser using Android JDK libraries exclusively. It works fine for any class whose fields are: primitive types, strings, one-dimensional arrays, or other classes. The problem now is to handle arrays of more dimensions. I'm a noob using reflection and JSON, so maybe I misconceived something.
You have to specify the Class you want to convert the JSON string. Then it basically iterates through all the fields in the class and search for a field in JSON with the same name. This works only for public methods (it's not a hard problem for me now, but if someone have an idea to improve it I'll appreciate as well).
My problem comes when I have an array of arrays, I've tried several ways but I'm not able to find a solution to deal with n-dimensional arrays. This is my method for arrays, the "TO-DO" part is the one I don't have a clue for do it. I've tried using the commented line, but it fails. Possibly it's the same problem in both directions, but I'm concerned now in decoding the JSON.
Everything solved!! Go to comments
I think it could be useful for more people, so I've uploaded the whole code here. http://pastebin.com/X7CmaxNf
The method insertArrayFromJSON() is called from public static Object populateObjectFromJSON(Class classname, JSONObject js) {} line 65th.
I've finally solved the problem by myself. I was stucked with this since yesterday because I was facing wrongly the array problem, but then I changed the method to attack it recursively in the right way. In the pastebin is the whole code ( I don't post here cause it's two hundred lines). Feel free for use it and if someone have some ideas to improve it, please tell me!.
http://pastebin.com/Jtf2SLDu
The main point was using Array.set(), Array.newInstance() and Array.get() methods properly. This is in lines 110-125 if someone wants to take a look.
For gain access to the protected&private methods I found the solution in this webiste. So now it works for any class with any public/protected/private field. http://tutorials.jenkov.com/java-reflection/private-fields-and-methods.html
I've made in a way that you can set the privacy desired before parsing.

Android: JSON or XML, caching

I'm working on a little Android project in java, I'm using the webapi of spotify to get me so data to play around with.
First thing I notice when visiting: https://developer.spotify.com/technologies/web-api/ is that a developer can choose to use xml or json.
What i would like to do is 'cache' my data so i can do the following:
read one value from the file, or construct an object based on different values
add the object created above to the lisviewadapter
update the listview with the updated adapter
iterate over previous steps until parsing of file is complete
I want to be as quick as possible for my users so that the ui gets updated while parsing and loading the data. For this I sketched 2 use-cases.
add items to the listview until done
show a X amount of items and show a load more button
What file type is more ideal to use for my problem? xml parsing or json parsing?
How can i do this parsing? which tools meet my requirements?
Which use-case seems better to use?
any tips if you have done something like this in the past?
any guidance is appreciated
I don't make any distinction between XML or JSON. To cache data you have two options. Either write the data to a file (will require reparsing of the file to extract the data (unless you create a new file of, for example, CSV data)) or write the required data to a database after parsing. As for updating ListView, that would be up to you based on the number of entries you have.
Android has both XML and JSON parsers built-in. You don't need GSON.
I'd recommend JSON because JSON uses less bandwitch for transfering and google has made an awesome json parser library called GSON.

Advice on managing a list of information

I have been studying Java for a little bit now, and I'm ready to try building something. I think I have the basic understanding of how to build simple parts, but I have a hard time planning out my project. I was hoping you guys could tell me what I would need to make it work.
I am creating an app for work. I work in the ATM business, and we provide tech support for all ATM models. So we have a master list of atm error codes, what models they apply to, their descriptions, and solutions.
From the App I would like to make it searchable by ATM manufacturer->Model->List of error codes to choose from. AND searchable by error code.
What I'm not sure about is how to save such a big list of codes. I've got them formatted like this:
("Hyosung", "1000", "20001", "Unable to Detect Cassette", "Remove and replace cassette - Check the micro-switch located on the inside left wall")
(MANUFACTURER, MODEL, CODE, DESCRIPTION, SOLUTION)
So depending on how the user chooses to search, it could pull all error
There are, maybe, 1000 error codes. Would it be best to save this to a text file that the app can access? How would you guys manage the error codes?
Store it in a SQLite database. It might be a slight overkill in this case, but it's flexible enough (and you really should learn about databases anyway).
Your error codes seem to be in CSV format. So:
On first use of application parse CSV file line by line using one of CSV parsing libs: http://opencsv.sourceforge.net/
Save every line of data as a row in database: http://developer.android.com/guide/topics/data/data-storage.html#db
Create a simple GUI where you enter error code and it returns all data for this error code.

Categories

Resources