2016-08-04 46 views
-1

Ich muss "Sprachen" von den unten angegebenen JSON zu analysieren, und müssen nur einmal tun und sie global in Android App verfügbar machen wollen. Bitte führen.Parsing Sprachen von gegebenen JSON Android

{ 
    "lastModifiedDate" : "8/4/2016 10:41 AM", 
    "languages": [{ 
     "EN" : [ 
      {"ERROR_CODE_INCORRECT_PIN": "Pin code is Invalid"}, 
      {"ERROR_CODE_404": "Server is not available"} 
     ], 
     "CZ" : [ 
      {"ERROR_CODE_INCORRECT_PIN": "Pin code is Invalid (CZ)"}, 
      {"ERROR_CODE_404": "Server is not available (CZ)"} 
     ] 
    }] 
} 
+2

Hallo und Willkommen zu SO, wenn Sie Ihre Code-Versuche so weit bereitstellen, dann wird die Gemeinschaft dazu neigen, dazu zu helfen, als "geben Sie mir Code" ohne Beweise der Mühe. Auf diese Weise können sie viel mehr Menschen helfen. – Visualife

+0

Mögliches Duplikat von [So parsen Sie JSON in Java] (http://stackoverflow.com/questions/2591098/how-to-parse-json-in-java) – Sufian

Antwort

1

Wenn Sie Gson Bibliothek Anwendung nichts ausmacht, Sie einfach eine Modellklasse für diese machen können, können Sie http://www.jsonschema2pojo.org/ anwenden, um Ihre Modellklasse

-----------------------------------com.sw.sample.CZ.java-------------------- 
package com.sw.sample; 
import javax.annotation.Generated; 
import com.google.gson.annotations.Expose; 
import com.google.gson.annotations.SerializedName; 

@Generated("org.jsonschema2pojo") 
public class CZ { 

@SerializedName("ERROR_CODE_INCORRECT_PIN") 
@Expose 
public String eRRORCODEINCORRECTPIN; 
@SerializedName("ERROR_CODE_404") 
@Expose 
public String eRRORCODE404; 

} 
-----------------------------------com.sw.sample.EN.java-------------------- 
package com.sw.sample; 

import javax.annotation.Generated; 
import com.google.gson.annotations.Expose; 
import com.google.gson.annotations.SerializedName; 

@Generated("org.jsonschema2pojo") 
public class EN { 

@SerializedName("ERROR_CODE_INCORRECT_PIN") 
@Expose 
public String eRRORCODEINCORRECTPIN; 
@SerializedName("ERROR_CODE_404") 
@Expose 
public String eRRORCODE404; 

} 
-----------------------------------com.sw.sample.Language.java-------------- 
package com.sw.sample; 

import java.util.ArrayList; 
import java.util.List; 
import javax.annotation.Generated; 
import com.google.gson.annotations.Expose; 
import com.google.gson.annotations.SerializedName; 

@Generated("org.jsonschema2pojo") 
public class Language { 

@SerializedName("EN") 
@Expose 
public List<EN> eN = new ArrayList<EN>(); 
@SerializedName("CZ") 
@Expose 
public List<CZ> cZ = new ArrayList<CZ>(); 

} 
-----------------------------------com.sw.sample.SampleModel.java----------- 
package com.sw.sample; 

import java.util.ArrayList; 
import java.util.List; 
import javax.annotation.Generated; 
import com.google.gson.annotations.Expose; 
import com.google.gson.annotations.SerializedName; 

@Generated("org.jsonschema2pojo") 
public class SampleModel { 

@SerializedName("lastModifiedDate") 
@Expose 
public String lastModifiedDate; 
@SerializedName("languages") 
@Expose 
public List<Language> languages = new ArrayList<Language>(); 

} 

Sie es in eine erstellen analysieren kann Objekt von

new Gson().fromJson(<your string here>,SampleModel.class); 

Sie können eine SampleModel Objekt in JSON String ändern, indem