如何映射此json响应正确性?

时间:2020-09-26 10:45:51

标签: java json gson

我无法将此Wikipedia opensearch json响应映射到我的模型。我正在使用gson映射响应

[
    "Computer",
    [
        "Computer",
        "Computer program",
        "Computer science",
        "Computer network",
        "Computer keyboard",
        "Computer mouse",
        "Computer security",
        "Computer virus",
        "Computer data storage",
        "Computer hardware"
    ],
    [
        "",
        "",
        "",
        "",
        "",
        "",
        "",
        "",
        "",
        ""
    ],
    [
        "https://en.wikipedia.org/wiki/Computer",
        "https://en.wikipedia.org/wiki/Computer_program",
        "https://en.wikipedia.org/wiki/Computer_science",
        "https://en.wikipedia.org/wiki/Computer_network",
        "https://en.wikipedia.org/wiki/Computer_keyboard",
        "https://en.wikipedia.org/wiki/Computer_mouse",
        "https://en.wikipedia.org/wiki/Computer_security",
        "https://en.wikipedia.org/wiki/Computer_virus",
        "https://en.wikipedia.org/wiki/Computer_data_storage",
        "https://en.wikipedia.org/wiki/Computer_hardware"
    ]
]

URL:https://en.wikipedia.org/w/api.php?action=opensearch&search=Computer&format=json

我的模特:

import lombok.Data;

@Data
public class OpensearchResponse {

    String searchTerm;

    String[] possibilities;

    String[] empty;

    String[] references;
    
}

当我尝试像这样映射json响应时:

var opensearchResponse = gson.fromJson(jsonResponse, OpensearchResponse.class);

我收到此错误

Exception in thread "main" com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $

我怀疑我的数据结构非常错误。但是到底是什么?

0 个答案:

没有答案