を使用してJSONを読むと、コードが動作しているようですが、2つの問題が、私はこのJSONを読んで問題を抱えていジャクソン
- それだけではない、完全に、JSONの1つのブロックを読み込みがあります。
- プロパティの値として常に「null」があります。
私はコンソールに組織されたjsonを表示しようとしていましたが、私はそれらを試してみると2つのことが起こります。 JSONデータの
サンプル:
{
"RestResponse" : {
"messages" : [ "More webservices are available at http://www.groupkt.com/post/f2129b88/services.htm", "Total [249] records found." ],
"result" : [ {
"name" : "Afghanistan",
"alpha2_code" : "AF",
"alpha3_code" : "AFG"
}, {
"name" : "Åland Islands",
"alpha2_code" : "AX",
"alpha3_code" : "ALA"
}, {
"name" : "Albania",
"alpha2_code" : "AL",
"alpha3_code" : "ALB"
}, ...
]
}
}
マイコード:
public class jsonController {
public void run() {
ObjectMapper mapper = new ObjectMapper();
try {
jsonHandler obj = mapper.readValue(new URL("http://services.groupkt.com/country/get/all"), jsonHandler.class);
//Organized Print
String organizedprint = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(obj);
System.out.println(organizedprint);
} catch (JsonGenerationException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
そしてメインに、私は
jsonController obj = new jsonController();
obj.run();
を持っていると、ここjsonHandlerが
@JsonIgnoreProperties(ignoreUnknown=true)
public class jsonHandler {
private String restResponse;
private String messages;
private String result;
private String name;
private String alpha2;
private String alpha3;
}
です
私が間違っていることを知っていますか?
jsonHandlerは何ですか?あなたのマッピングクラスですか?投稿できますか? –
@fabienbkそこには、ゲッターとセッターがあります。私はそれを短くするためにここに入れませんでした。 – JuanPa
ありがとうございます。以下の私の回答を参照してください。 –