Java解析Json响应字符串

huangapple 未分类评论45阅读模式
标题翻译

Java Parse Json response string

问题

{
    "count": 61,
    "next": "https://swapi.co/api/planets/?page=2",
    "previous": null,
    "results": [
        {
            "name": "Alderaan",
            "rotation_period": "24"
        },
        {
            "name": "Yavin IV",
            "rotation_period": "24"
        }
    ]
}
String responseString = content.toString();
System.out.println(responseString);
JSONObject jsonObject = new JSONObject(responseString);

Error:
JSONObject请求映射错误
英文翻译
{
    "count": 61,
    "next": "https://swapi.co/api/planets/?page=2",
    "previous": null,
    "results": [
        {
            "name": "Alderaan",
            "rotation_period": "24",
        },
        {
            "name": "Yavin IV",
            "rotation_period": "24",
        },

    ]
}

How I can convert to Array? Whe JsonObject Requires Map?

    String responseString=content.toString();
    System.out.println(responseString);
    JSONObject jsonObject = new JSONObject(responseString);

Error:
JSONObject request map

huangapple
  • 本文由 发表于 2020年3月17日 03:42:25
  • 转载请务必保留本文链接:https://java.coder-hub.com/60712279.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定