Привет всем,Как разобрать сложную строку JSON, полученную из ответа webservice с помощью GSON в Java?
I am new to Json/Gson. I have already looked all around the internet for help, but I have seen nothing so similar to what I need to parse. So I am posting here, any help will be appreciated.
Я получаю в ответ от веб-сервиса, я звоню этот JSon Строка:
Json String = {"courses":[{"links": [{"href":"https://xp.student.com/courses/6364145","rel":"self","title":"course"}]}, {"links": [{"href":"https://xp.student.com/courses/6364143","rel":"self","title":"course"}]},
{"links": [{"href":"https://xp.student.com/courses/6364144","rel":"self","title":"course"}]}]}
Я уже сделал код до того момента, когда я получаю «Json Строка ":
InputStreamReader reader = new InputStreamReader(httpConn.getInputStream());
in = new BufferedReader(reader);
Gson gson = new Gson();
Course courses = new Gson().fromJson(in,Course.class);
Я также создал следующие классы:
import ccSample.Type.Course.Link;
public class Course {
public Link links[];
}
public class Link{
public String href;
public String rel;
public String title;
public String getHref() {
return href;
}
public void setHref(String href) {
this.href = href;
}
public String getRel() {
return rel;
}
public void setRel(String rel) {
this.rel = rel;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
but I am just getting a null courses object and do not know what I am missing, any suggestions corrections are welcome!
Thank you very much :)