Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Using Gson to Solve</strong><br> I would create a class for individual parameter in the json String. Alternatively you can create one main class called "Data" and then create inner classes similarly. I created separate classes for clarity.</p> <p>The classes are as follows.</p> <ul> <li>Data </li> <li>Translations </li> <li>TranslatedText</li> </ul> <p>In the class JsonParsing the method "parse" we call <code>gson.fromJson(jsonLine, Data.class)</code> which will convert the String in java objects using Reflection.</p> <p>Once we have access to the "Data" object we can access each parameter individually.</p> <p>Didn't get a chance to test this code as I am away from my dev machine. But this should help.</p> <p><strong>Some good examples and articles.</strong><br> <a href="http://albertattard.blogspot.com/2009/06/practical-example-of-gson.html" rel="noreferrer">http://albertattard.blogspot.com/2009/06/practical-example-of-gson.html</a> <br> <a href="http://sites.google.com/site/gson/gson-user-guide" rel="noreferrer">http://sites.google.com/site/gson/gson-user-guide</a></p> <p><strong>Code</strong></p> <pre><code>public class JsonParsing{ public void parse(String jsonLine) { Gson gson = new GsonBuilder().create(); Data data = gson.fromJson(jsonLine, Data.class); Translations translations = data.getTranslation(); TranslatedText[] arrayTranslatedText = translations.getArrayTranslatedText(); //this returns an array, based on json string for(TranslatedText translatedText:arrayTranslatedText ) { System.out.println(translatedText.getArrayTranslatedText()); } } } public class Data{ private Translations translations; public Translations getTranslation() { return translations; } public void setTranslation(Translations translations) { this.translations = translations; } } public class Translations { private TranslatedText[] translatedText; public TranslatedText[] getArrayTranslatedText() { return translatedText; } public void setTranslatedText(TranslatedText[] translatedText) { this.translatedText= translatedText; } } public class TranslatedText { private String translatedText; public String getTranslatedText() { return translatedText; } public void setTranslatedText(String translatedText) { this.translatedText = translatedText; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload