久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

從 JSON 獲取數據

Getting data from JSON(從 JSON 獲取數據)
本文介紹了從 JSON 獲取數據的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試從這個 JSON 字符串中獲取值,但我很難做到這一點.

I'm trying to get the values out of this JSON string but I'm having a hard time achieving this.

{"DebugLogId":"1750550","RequestId":"17505503","Result":
{"Code":"","DebugLogId":"1750550","Message":""},
    "Suggestions":[
        {"Ranking":"1","Score":"60","Title":"This is a test message 1"},
        {"Ranking":"2","Score":"60","Title":"This is a test message 2"}         
    ]}

什么方法最容易訪問建議"中的數據?我正在使用 GSON 模塊.理想情況下,我想把它全部放在一個 HashMap 中.

What way would be easiest to access the data in 'Suggestions'? I'm using the GSON module. Ideally I would like to put it all in a HashMap.

感謝您的幫助和/或建議!

Thanks for any help and/or suggestions!

感謝您的幫助!

推薦答案

希望對你有幫助:

App.java:

package sg.java.play_sof_json_6596072;

import com.google.gson.Gson;

public class App {
    public static void main(String[] args) {
        Gson gson = new Gson();
        String jsonString = "{"DebugLogId":"1750550","RequestId":"17505503","Result":{"Code":"","DebugLogId":"1750550","Message":""},"Suggestions":[{"Ranking":"1","Score":"60","Title":"This is a test message 1"},{"Ranking":"2","Score":"60","Title":"This is a test message 2"}]}";

        Debug obj = (Debug) gson.fromJson(jsonString, Debug.class);

        System.out.println(obj.getSuggestionList().get(1).getTitle());

    }
}

Debug.java:

Debug.java:

package sg.java.play_sof_json_6596072;

import java.util.List;

import com.google.gson.annotations.SerializedName;

public class Debug {
    @SerializedName("DebugLogId")
    private String debugLogId;
    @SerializedName("RequestId")
    private String requestId;
    @SerializedName("Result")
    private Result result;
    @SerializedName("Suggestions")
    private List<Suggestion> suggestionList;

    /**
     * @return the debugLogId
     */
    public final String getDebugLogId() {
        return this.debugLogId;
    }

    /**
     * @param debugLogId the debugLogId to set
     */
    public final void setDebugLogId(String debugLogId) {
        this.debugLogId = debugLogId;
    }

    /**
     * @return the requestId
     */
    public final String getRequestId() {
        return this.requestId;
    }

    /**
     * @param requestId the requestId to set
     */
    public final void setRequestId(String requestId) {
        this.requestId = requestId;
    }

    /**
     * @return the result
     */
    public final Result getResult() {
        return this.result;
    }

    /**
     * @param result the result to set
     */
    public final void setResult(Result result) {
        this.result = result;
    }

    /**
     * @return the suggestionList
     */
    public final List<Suggestion> getSuggestionList() {
        return this.suggestionList;
    }

    /**
     * @param suggestionList the suggestionList to set
     */
    public final void setSuggestionList(List<Suggestion> suggestionList) {
        this.suggestionList = suggestionList;
    }

}

結果.java:

package sg.java.play_sof_json_6596072;

import com.google.gson.annotations.SerializedName;

public class Result {
    @SerializedName("Code")
    private String code;
    @SerializedName("DebugLogId")
    private String debugLogId;
    @SerializedName("Message")
    private String messahe;

    /**
     * @return the code
     */
    public final String getCode() {
        return this.code;
    }

    /**
     * @param code the code to set
     */
    public final void setCode(String code) {
        this.code = code;
    }

    /**
     * @return the debugLogId
     */
    public final String getDebugLogId() {
        return this.debugLogId;
    }

    /**
     * @param debugLogId the debugLogId to set
     */
    public final void setDebugLogId(String debugLogId) {
        this.debugLogId = debugLogId;
    }

    /**
     * @return the messahe
     */
    public final String getMessahe() {
        return this.messahe;
    }

    /**
     * @param messahe the messahe to set
     */
    public final void setMessahe(String messahe) {
        this.messahe = messahe;
    }

}

Suggestion.java:

Suggestion.java:

package sg.java.play_sof_json_6596072;

import com.google.gson.annotations.SerializedName;

public class Suggestion {
    @SerializedName("Ranking")
    private String ranking;
    @SerializedName("Score")
    private String score;
    @SerializedName("Title")
    private String title;

    /**
     * @return the ranking
     */
    public final String getRanking() {
        return this.ranking;
    }

    /**
     * @param ranking the ranking to set
     */
    public final void setRanking(String ranking) {
        this.ranking = ranking;
    }

    /**
     * @return the score
     */
    public final String getScore() {
        return this.score;
    }

    /**
     * @param score the score to set
     */
    public final void setScore(String score) {
        this.score = score;
    }

    /**
     * @return the title
     */
    public final String getTitle() {
        return this.title;
    }

    /**
     * @param title the title to set
     */
    public final void setTitle(String title) {
        this.title = title;
    }

}

這篇關于從 JSON 獲取數據的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Convert List of Strings into Map using Java-8 Streams API(使用 Java-8 Streams API 將字符串列表轉換為 Map)
java linkedhashmap iteration(javalinkedhashmap迭代)
Converting a list of objects to Map(將對象列表轉換為 Map)
Create a HashMap with a fixed Key corresponding to a HashSet. point of departure(用一個固定的Key對應一個HashSet創建一個HashMap.出發點)
HttpMessageConverter exception : RestClientException: Could not write request: no suitable HttpMessageConverter found(HttpMessageConverter 異常:RestClientException:無法寫入請求:找不到合適的 HttpMessageConverter) - IT屋-程序員
Best way to order an HashMap by key in Java?(在 Java 中按鍵排序 HashMap 的最佳方法?)
主站蜘蛛池模板: 欧美激情精品久久久久久 | 日韩综合在线 | 国产精品久久免费观看 | 久久久夜色精品亚洲 | 国产精品亚洲一区二区三区在线 | 美女视频黄的免费 | 超碰免费在 | 日韩中文一区 | a黄视频| 国产91久久久久蜜臀青青天草二 | 国产精品久久久久久吹潮日韩动画 | 91在线成人 | 日韩在线免费视频 | 日韩精品一区二区三区高清免费 | 亚洲精品欧美 | 久久亚洲一区二区三区四区 | 国产精品久久久久久久久久久久 | 久久国产精品一区二区三区 | 一区二区视频 | 99久久亚洲 | 免费观看黄a一级视频 | 一区二区三区精品视频 | 欧美一区二区三区视频 | 免费在线观看av网站 | 国产精品久久久亚洲 | zzzwww在线看片免费 | 久久久久久国产精品免费 | 日韩视频区| 免费观看av | 色橹橹欧美在线观看视频高清 | 五月天婷婷激情 | 精品在线免费看 | 日韩成人精品视频 | 国产日韩视频在线 | 米奇狠狠鲁 | 日韩无 | 精品在线免费观看视频 | 精品av| 午夜欧美 | 欧美成人精品二区三区99精品 | 91精品久久久久久久99 |