Answer the question
In order to leave comments, you need to log in
Why does it print null when I parse JSON?
I parse the site's API https://api.qrfinex.com/v1.1/actions
like this json looks like
I get data like this
public static void main(String[] args) throws ParserConfigurationException, IOException, SAXException {
ArrayList<String> xmlArrayList = new ArrayList<String>();
URL url;
URLConnection uc;
StringBuilder parsedContentFromUrl = new StringBuilder();
String urlString = "https://api.qrfinex.com/v1.1/actions";
System.out.println("Getting content for URl : " + urlString);
url = new URL(urlString);
uc = url.openConnection();
uc.connect();
uc = url.openConnection();
uc.addRequestProperty("User-Agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
uc.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream(), "UTF-8"));
int ch;
while ((ch = in.read()) != -1) {
parsedContentFromUrl.append((char) ch);
}
System.out.println(parsedContentFromUrl);
// получаем данные из сайта
//==========================================================================
// преобразуем полученные данные
Gson gson = new Gson();
RootObject response = gson.fromJson(String.valueOf(parsedContentFromUrl), RootObject.class);
System.out.println(response.getActions());
public class Provider {
private int id;
private String name;
private String icon;
private String web;
private String ios;
private String android;
@JsonProperty("id")
public int getId() {
return id;
}
@JsonProperty("id")
public void setId(int id) {
this.id = id;
}
@JsonProperty("name")
public String getName() {
return name;
}
@JsonProperty("name")
public void setName(String name) {
this.name = name;
}
@JsonProperty("icon")
public String getIcon() {
return icon;
}
@JsonProperty("icon")
public void setIcon(String icon) {
this.icon = icon;
}
@JsonProperty("web")
public String getWeb() {
return web;
}
@JsonProperty("web")
public void setWeb(String web) {
this.web = web;
}
@JsonProperty("ios")
public String getIos() {
return ios;
}
@JsonProperty("ios")
public void setIos(String ios) {
this.ios = ios;
}
@JsonProperty("android")
public String getAndroid() {
return android;
}
@JsonProperty("android")
public void setAndroid(String android) {
this.android = android;
}
}
public class RootObject {
private Provider[] providers;
private Actions actions;
@JsonProperty("providers")
public Provider[] getProviders() {
return providers;
}
@JsonProperty("providers")
public void setProviders(Provider[] providers) {
this.providers = providers;
}
@JsonProperty("actions")
public Actions getActions() {
return actions;
}
@JsonProperty("actions")
public void setActions(Actions actions) {
this.actions = actions;
}
}
Answer the question
In order to leave comments, you need to log in
inside the providers there is also a List Item, perhaps because of this it does not work
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question