Как разобрать данные JSON в Android? - PullRequest
0 голосов
/ 08 октября 2018

Как мне разобрать ниже данные JSON в Android, и я хочу отобразить их в виде переработчика

{"scode":"200","video_limit":"4","app_category":{"cat1":{"app_menu_id":"19","app_menu_name":"Love","video":[{"app_video_id":"1","app_video_name":"video1","app_video_path":"vid1.mp4","app_video_image_path":"vid1.jpg","app_menu_id":"19","app_sub_menu_id":"0","app_menu_name":"Love"},{"app_video_id":"2","app_video_name":"vid2","app_video_path":"vid2.mp4","app_video_image_path":"vid2.jpg","app_menu_id":"19","app_sub_menu_id":"0","app_menu_name":"Love"},{"app_video_id":"4","app_video_name":"vid3","app_video_path":"vid3.mp4","app_video_image_path":"vid3.jpg","app_menu_id":"19","app_sub_menu_id":"0","app_menu_name":"Love"},{"app_video_id":"5","app_video_name":"vid4","app_video_path":"vid4.mp4","app_video_image_path":"vid4.jpg","app_menu_id":"19","app_sub_menu_id":"0","app_menu_name":"Love"}]},"cat2":{"app_menu_id":"21","app_menu_name":"Sad","video":[{"app_video_id":"3","app_video_name":"vid5","app_video_path":"vid5.mp4","app_video_image_path":"vid5.jpg","app_menu_id":"21","app_sub_menu_id":"0","app_menu_name":"Sad"},{"app_video_id":"6","app_video_name":"vid6","app_video_path":"vid6.mp4","app_video_image_path":"vid6.jpg","app_menu_id":"21","app_sub_menu_id":"0","app_menu_name":"Sad"},{"app_video_id":"8","app_video_name":"vid7","app_video_path":"vid7.mp4","app_video_image_path":"vid7.jpg","app_menu_id":"21","app_sub_menu_id":"0","app_menu_name":"Sad"},{"app_video_id":"9","app_video_name":"vid8","app_video_path":"vid8.mp4","app_video_image_path":"vid8.jpg","app_menu_id":"21","app_sub_menu_id":"0","app_menu_name":"Sad"}]}}}

1 Ответ

0 голосов
/ 08 октября 2018

Использовать GsonConverter

https://github.com/square/retrofit/tree/master/retrofit-converters/gson

его использование приведено ниже.

public class Action {

@SerializedName("uuid")
private String uuid;

@SerializedName("type")
private String type;

@SerializedName("celebrity_base")
private CelebrityBase celebrity_base;

@SerializedName("topic")
private Topic topic;

@SerializedName("profession")
private Profession profession;

@SerializedName("movie")
private Movie movie;

@SerializedName("album")
private Album album;

@SerializedName("track")
private Track track;

@SerializedName("tournament")
private Tournament tournament;

@SerializedName("match")
private Match match;

@SerializedName("book")
private Book book;

@SerializedName("hashtags")
private List<HashTag> hashTags;

@SerializedName("target_persons")
@Expose
private List<TargetPersons> targetPersons;

@SerializedName("top_comments")
private List<TopComment> actionComments;

@SerializedName("title")
private String title;

@SerializedName("subtitle")
private String subtitle;

@SerializedName("description")
private String description;

@SerializedName("from_date")
private String from_date;

@SerializedName("to_date")
private String to_date;

@SerializedName("rate")
private double rate;

@SerializedName("rate_count")
private int rate_count;

@SerializedName("persian_rate")
private String persian_rate;

@SerializedName("persian_rate_count")
private String persian_rate_count;

@SerializedName("image_link")
private String image_link;

@SerializedName("picture")
private String picture;

@SerializedName("relation_type")
private String relation_type;

@SerializedName("persian_user_rate")
private int persian_user_rate;

@NonNull
public String getUuid() {
    return uuid;
}

public void setUuid(@NonNull String uuid) {
    this.uuid = uuid;
}

@NonNull
public String getType() {
    return type;
}

public void setType(@NonNull String type) {
    this.type = type;
}

@Nullable
public CelebrityBase getCelebrity_base() {
    return celebrity_base;
}

public void setCelebrity_base(@Nullable CelebrityBase celebrity_base) {
    this.celebrity_base = celebrity_base;
}

@Nullable
public Topic getTopic() {
    return topic;
}

public void setTopic(@Nullable Topic topic) {
    this.topic = topic;
}

@Nullable
public Profession getProfession() {
    return profession;
}

public void setProfession(@Nullable Profession profession) {
    this.profession = profession;
}

@Nullable
public Movie getMovie() {
    return movie;
}

public void setMovie(@Nullable Movie movie) {
    this.movie = movie;
}

@Nullable
public Album getAlbum() {
    return album;
}

public void setAlbum(@Nullable Album album) {
    this.album = album;
}

@Nullable
public Track getTrack() {
    return track;
}

public void setTrack(@Nullable Track track) {
    this.track = track;
}

@Nullable
public Tournament getTournament() {
    return tournament;
}

public void setTournament(@Nullable Tournament tournament) {
    this.tournament = tournament;
}

@Nullable
public Match getMatch() {
    return match;
}

public void setMatch(@Nullable Match match) {
    this.match = match;
}

@Nullable
public Book getBook() {
    return book;
}

public void setBook(@Nullable Book book) {
    this.book = book;
}

@Nullable
public List<HashTag> getHashTags() {
    return hashTags;
}

public void setHashTags(@Nullable List<HashTag> hashTags) {
    this.hashTags = hashTags;
}

@Nullable
public List<TopComment> getActionComments() {
    return actionComments;
}

public void setActionComments(@Nullable List<TopComment> actionComments) {
    this.actionComments = actionComments;
}

public String getTitle() {
    return title;
}

public void setTitle(String title) {
    this.title = title;
}

@Nullable
public String getSubtitle() {
    return subtitle;
}

public void setSubtitle(@Nullable String subtitle) {
    this.subtitle = subtitle;
}

@Nullable
public String getDescription() {
    return description;
}

public void setDescription(@Nullable String description) {
    this.description = description;
}

@Nullable
public String getFrom_date() {
    return from_date;
}

public void setFrom_date(@Nullable String from_date) {
    this.from_date = from_date;
}

@Nullable
public String getTo_date() {
    return to_date;
}

public void setTo_date(@Nullable String to_date) {
    this.to_date = to_date;
}

@Nullable
public double getRate() {
    return rate;
}

public void setRate(@Nullable double rate) {
    this.rate = rate;
}

@Nullable
public int getRate_count() {
    return rate_count;
}

public void setRate_count(@Nullable int rate_count) {
    this.rate_count = rate_count;
}

@Nullable
public String getPersian_rate() {
    return persian_rate;
}

public void setPersian_rate(@Nullable String persian_rate) {
    this.persian_rate = persian_rate;
}

@Nullable
public String getPersian_rate_count() {
    return persian_rate_count;
}

public void setPersian_rate_count(@Nullable String persian_rate_count) {
    this.persian_rate_count = persian_rate_count;
}

@Nullable
public String getImage_link() {
    return image_link;
}

public void setImage_link(@Nullable String image_link) {
    this.image_link = image_link;
}

@Nullable
public String getPicture() {
    return picture;
}

public void setPicture(@Nullable String picture) {
    this.picture = picture;
}

@Nullable
public String getRelation_type() {
    return relation_type;
}

public void setRelation_type(@Nullable String relation_type) {
    this.relation_type = relation_type;
}

@Nullable
public int getPersian_user_rate() {
    return persian_user_rate;
}

public void setPersian_user_rate(@Nullable int persian_user_rate) {
    this.persian_user_rate = persian_user_rate;
}

public List<TargetPersons> getTargetPersons() {
    return targetPersons;
}

public void setTargetPersons(List<TargetPersons> targetPersons) {
    this.targetPersons = targetPersons;
}
}
...