2016-10-12 1 views
-2
{ 
"success":"true", 
"contacts": { 
"member" : [ 
"name" : "x"; 
"phone" : "43323284" 
} 
]; 
"invitation":[ 
{ 
"name":"y" 
"phone":"78994993" 
} 
], 
"invite":[ 
{ 
"name":"z" 
"contact:"567896789" 
} 
] 
} 

Dies ist meine Antwort bekommen zu analysieren, das Gesicht ich Schwierigkeiten this.Please schlägt mich zu analysieren, wie diese Art von jsonGibt es eine Möglichkeit, diese json Antwort in android

+1

nicht möglich mit dem heutigen Stand der Technik, sorry – Dportology

+2

Mögliche Duplikat von [Wie parsen JSON in Java] (http://stackoverflow.com/questions/2591098/how-to-parse-json-in-java) – Vall0n

+0

In Bezug auf Menschen, die Ihnen helfen, können Sie Ihren Code korrekt formatieren? –

Antwort

0

Die JSON ist keine gültige. Ich habe Ihre JSON bearbeitet.

{ 
"success":"true", 
"contacts": { 
"member" : [{"name" : "x","phone" : "43323284"}], 
"invitation":[{"name":"y","phone":"78994993"}], 
"invite":[{"name":"z","contact":"567896789"}] 
} 
} 

Ihre Modellklassen bauen wie:

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

public class Example { 

@SerializedName("success") 
@Expose 
private String success; 
@SerializedName("contacts") 
@Expose 
private Contacts contacts; 

public String getSuccess() { 
return success; 
} 

public void setSuccess(String success) { 
this.success = success; 
} 

public Contacts getContacts() { 
return contacts; 
} 

public void setContacts(Contacts contacts) { 
this.contacts = contacts; 
} 

} 


public class Contacts { 

@SerializedName("member") 
@Expose 
private List<Member> member = new ArrayList<Member>(); 
@SerializedName("invitation") 
@Expose 
private List<Invitation> invitation = new ArrayList<Invitation>(); 
@SerializedName("invite") 
@Expose 
private List<Invite> invite = new ArrayList<Invite>(); 

public List<Member> getMember() { 
return member; 
} 

public void setMember(List<Member> member) { 
this.member = member; 
} 

public List<Invitation> getInvitation() { 
return invitation; 
} 


public void setInvitation(List<Invitation> invitation) { 
this.invitation = invitation; 
} 


public List<Invite> getInvite() { 
return invite; 
} 


public void setInvite(List<Invite> invite) { 
this.invite = invite; 
} 

} 


public class Invitation { 

@SerializedName("name") 
@Expose 
private String name; 
@SerializedName("phone") 
@Expose 
private String phone; 

public String getName() { 
return name; 
} 

public void setName(String name) { 
this.name = name; 
} 

public String getPhone() { 
return phone; 
} 

public void setPhone(String phone) { 
this.phone = phone; 
} 

} 


public class Invite { 

@SerializedName("name") 
@Expose 
private String name; 
@SerializedName("contact") 
@Expose 
private String contact; 

public String getName() { 
return name; 
} 

public void setName(String name) { 
this.name = name; 
} 

public String getContact() { 
return contact; 
} 

public void setContact(String contact) { 
this.contact = contact; 
} 

} 


public class Member { 

@SerializedName("name") 
@Expose 
private String name; 
@SerializedName("phone") 
@Expose 
private String phone; 

public String getName() { 
return name; 
} 

public void setName(String name) { 
this.name = name; 
} 

public String getPhone() { 
return phone; 
} 

public void setPhone(String phone) { 
this.phone = phone; 
} 
} 

Um das Objekt aus dem json zu erhalten:

Example obj = new Gson().fromJson(jsonObject, Example.class); 
+0

Thankxx für Ihre Hilfe. –

0

Zunächst erstellen Modellklasse zu analysieren. Und:

Gson gson = new Gson(); 
ModelClass model = gson.fromJson(jsonString, ModelClass.class); 

Es gibt viele Optionen sind json zu analysieren. Für weitere Details: https://stackoverflow.com/a/31743324/7001152

+0

thankxx für Ihre Hilfe –

Verwandte Themen