I have looked through the forum and have across some similar question but none of which have been of any aid.
So I am taking up from where someone else has left off and this is where the issue lies. The code I'm working on uses gson to parse the json stream and that's fine and clear, then relevant data is then added to a parcel. Like below
public class JsonAssets{
String Address;
String Title;
String File;
Category [] Categories;
public void writeToParcel(Parcel paramParcel, int paramInt) {
paramParcel.writeString(Address);
paramParcel.writeString(Title);
paramParcel.writeString(AudioFile);
}
private JsonAsset(Parcel in) {
Address = in.readString();
Title = in.readString();
AudioFile = in.readString();
}
public ContentValues getContentValues(){
ContentValues contentValue = new ContentValues();
contentValue.put("ID", this.Id);
contentValue.put("Title", this.Title);
contentValue.put("address", this.Address);
}
EDIT
private class Category{
String CategoryName;
String Description;
String ExternalLink;
String File;
String FileName;
int CategoryID;
int ParentCategoryID;
int Id;
int Image;
public int getCategoryID(){
return this.Id;
}
}
The database is then update with these contentValues.
The JSON looks something like this:
"assets":[
{
"Address":"Crator1, The Moon",
"Title":"The Moon",
"AudioFile":null,
"Categories":[
{
"CategoryName":"Restaurants",
"Description":"blah blah",
"ExternalLink":"",
"File":"",
"FileName":"0",
"CategoryID":0,
"ParentCategoryID":786,
"Id":334,
"Image":"",
},
I know that JSON isn't valid, I've just edited to suit. The problem is I have Categories, a nested array and I don't know how to handle that array. All I'm looking to get is the 'Id' in the Categories array.
I can't create a seperate object for it because of how the class is passed:
JsonReader reader = new JsonReader(new InputStreamReader(is, "UTF-8"));
reader.beginObject();
reader.nextName();
reader.beginArray();
JsonObject obj = null;
while (reader.hasNext()) {
try{
switch(type){
case ASSET_UPDATE:
obj = gson.fromJson(reader, JsonAsset.class);
break;
}
So if anyone could tell me how to handle this, I'd greatly appreciate it. If I'm not very clear in my question apologies, just ask and I'll clarify...thanks in advance