by
313 10
1
5
2,644
0
Top 1% !
Popular
Famous
Specified
OpenSource
Popularity: 6459th place
No tags for this snippet yet.
Android Version4.0 Icecream Sandwich
LanguageJava
LicenseMIT_X11
OSAndroid

Android

JSON parsing with Jackson
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/138732/Android?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
String response = event.getJsonLibraryMetadata(); JsonFactory jf = new JsonFactory(); try { // Log.i("JSON", response); JsonParser jp = jf.createParser(response); while (jp.nextToken() != JsonToken.END_OBJECT) { String token = jp.getCurrentName(); if ("ebooks".equals(token)) { // System.out.println("ebooks :"); EBookDetails mEBookDetails = new EBookDetails(); // the next token will be '[' that means that we have an // array jp.nextToken(); // parse tokens until you find ']' while (jp.nextToken() != JsonToken.END_ARRAY) { // System.out.println(jp.getText()); String currentToken = jp.getCurrentName(); if ("cover_thumbnail".equals(currentToken)) { jp.nextToken(); } if ("scriptures".equals(currentToken)) { jp.nextToken(); } if ("sample".equals(currentToken)) { jp.nextToken(); } if ("created_at".equals(currentToken)) { jp.nextToken(); } if ("updated_at".equals(currentToken)) { jp.nextToken(); } if ("id".equals(currentToken)) { jp.nextToken(); mEBookDetails.id = jp.getIntValue();// ("id"); } if ("archived".equals(currentToken)) { jp.nextToken(); mEBookDetails.isArchived = jp.getValueAsBoolean(); // .getBoolean("archived"); } if ("title".equals(currentToken)) { jp.nextToken(); mEBookDetails.title = jp.getValueAsString();// getString("title"); products.add(mEBookDetails.title); } if ("description".equals(currentToken)) { jp.nextToken(); mEBookDetails.description = jp.getValueAsString(); // .getString("description"); } if ("author".equals(currentToken)) { jp.nextToken(); mEBookDetails.author = jp.getValueAsString();// .getString("author"); } if ("file_name".equals(currentToken)) { jp.nextToken(); mEBookDetails.file_name = jp.getValueAsString();// .getString("file_name"); } if ("genres".equals(currentToken)) { jp.skipChildren(); // while (jp.nextToken() != JsonToken.END_ARRAY) { // // } } if ("authors".equals(currentToken)) { jp.skipChildren(); // while (jp.nextToken() != JsonToken.END_ARRAY) { // // } } if ("topics".equals(currentToken)) { jp.skipChildren(); // while (jp.nextToken() != JsonToken.END_ARRAY) { // } } if ("cover_url".equals(currentToken)) { jp.nextToken(); mEBookDetails.cover_url = jp.getValueAsString();// .getString("cover_url"); // XXX- Stancho - speed optimization String key = "B" + mEBookDetails.id; // XXX- Stancho - speed optimization - // reduce the number of String adding app.book_list.put(key, mEBookDetails); mEBookDetails = new EBookDetails(); } } } } jp.close();
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus