Answer the question
In order to leave comments, you need to log in
How to save photos to a VK album using vk api?
I received a link to download the image, then I uploaded the photo to the server and received such a response from it (I'll attach it below). How to save it in Java? It's just that, as I understand it, there is an array of objects in which there are some fields and other arrays, I just can't find a suitable way to solve the situation.
{"server":516536,
"photos_list":"[{\"markers_restarted\":true,\"photo\":\"6cee9fe460:w\",\"sizes\":
[],\"latitude\":0,\"longitude\":0,\"kid\":\"846e5d314fae29c18cd32d71c8979740\",\"sizes2\":
,\"urls\":
[],\"urls2\":
[\"71xi0bP9G6AqAm6g7F_xwL-JwBIX1DfR_hTcmQ/cU4O55r9E3A.jpg\",
\"JR_VdDD7iGP7-j5MonCCDpXbWfh8U4w6Wc8fQw/zseeojuRUHo.jpg\",
\"Wj3pXyoa-wGHxyFlqDDf9ZtiY6QAQi9MF2barw/lgL3O5oe3fk.jpg\",
\"D9PClJar5WrT2KTdoS6zR6yoRyqNk_kNi27ofQ/r-y89Xhb6VQ.jpg\",
\"CyCyOBuf9cArqqq2Yeu7cdy97-KvVi-zJEdVsQ/yIOlSAN4NfY.jpg\",
\"opyOpYqJTqI2MaBCiBkc7PUeCf1DlKWVsTj-GA/kQkv0m4_yhY.jpg\",
\"JR_VdDD7iGP7-j5MonCCDpXbWfh8U4w6Wc8fQw/zseeojuRUHo.jpg\",
\"nRXlFSPyEcYKklVXKYu7ES66i5rr56j7RogBUA/Zm4XBv0w5e8.jpg\",
\"LKSKZNRik2OFkOn1k88y-WymV9WZdoL22dr_zA/xai_25gSinc.jpg\",
\"5L3WDambkaMGryhkMgbz9lejjxJdpq23ZrcX_g/_bRHsQDza6Q.jpg\"]}]",
"aid":280638576,
"hash":"3c48d19de32998df74fe99f293ca25c3"}
Answer the question
In order to leave comments, you need to log in
Good afternoon!
You received json in response.
Now, you need to deserialize the response into an object.
You can use the jackson or gson libraries, or you can use the DOM Parser (built-in java tools).
You can generate a json structure here:
https://www.jsonschema2pojo.org/
Here, for jackson:
import java.util.List;
import javax.annotation.Generated;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"markers_restarted",
"photo",
"sizes",
"latitude",
"longitude",
"kid",
"sizes2",
"urls",
"urls2"
})
@Generated("jsonschema2pojo")
public class Photos {
@JsonProperty("markers_restarted")
public Boolean markersRestarted;
@JsonProperty("photo")
public String photo;
@JsonProperty("sizes")
public List<Object> sizes = null;
@JsonProperty("latitude")
public Integer latitude;
@JsonProperty("longitude")
public Integer longitude;
@JsonProperty("kid")
public String kid;
@JsonProperty("sizes2")
public List<List<String>> sizes2 = null;
@JsonProperty("urls")
public List<Object> urls = null;
@JsonProperty("urls2")
public List<String> urls2 = null;
}
import java.util.List;
import javax.annotation.Generated;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"server",
"photos_list",
"aid",
"hash"
})
@Generated("jsonschema2pojo")
public class Example {
@JsonProperty("server")
public Integer server;
@JsonProperty("photos_list")
public List<Photos> photosList = null;
@JsonProperty("aid")
public Integer aid;
@JsonProperty("hash")
public String hash;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question