This is my json object structure:
object {1}
products [3]
0 {14}
1 {14}
2 {14}
and here is my code:
gitapi.java
public interface gitapi {
@GET("/admin/API/{user}")
public void getFeed(@Path("user") String user, Callback<gitmodel> response);
}
MainActivity.java
Button click;
TextView tv;
EditText edit_user;
ProgressBar pbar;
String API = "http://xxyyzz.com"; //BASE URL
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
click = (Button) findViewById(R.id.button);
tv = (TextView) findViewById(R.id.tv);
edit_user = (EditText) findViewById(R.id.edit);
pbar = (ProgressBar) findViewById(R.id.pb);
pbar.setVisibility(View.INVISIBLE);
click.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String user = edit_user.getText().toString();
pbar.setVisibility(View.VISIBLE);
//Retrofit section start from here...
RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint(API).build(); //create an adapter for retrofit with base url
gitapi git = restAdapter.create(gitapi.class); //creating a service for adapter with our GET class
//Now ,we need to call for response
//Retrofit using gson for JSON-POJO conversion
git.getFeed(user, new Callback<gitmodel>() {
@Override
public void success(gitmodel gitmodel, Response response) {
//we get json object from github server to our POJO or model class
tv.setText("getTitle :" + gitmodel.getTitle());
pbar.setVisibility(View.INVISIBLE); //disable progressbar
}
@Override
public void failure(RetrofitError error) {
tv.setText(error.getMessage());
pbar.setVisibility(View.INVISIBLE); //disable progressbar
}
});
}
});
}
The problem is I dont know how to access the inner json objects. Is there a way to do this.
from jsonschemaa2pojo.com i got the pojo file as 2 files one for gitmodel.java and other for product.java. My Question is how can i access the objects within the json object.
Ex: you can see the tv.setText("getTitle :" + gitmodel.getTitle()); in MainActivity.java which is what i want to achieve. i want to call the methods in order to access the inner object. Thank you...
gitmodel.getInnerObject()... orgitmodel.getObjectList().get(x)... there are bazillions topic about json, please don't be lazy and do some reasearch before askinggitmodel.getInnerObject()should returnsInnerModel(similar to gitmodel but should define inner complex property)...InnerModelshould haveinnerpropertyand setter/getter ... so now you can usegitmodel.getInnerObject().getInnerProperty()... in other words: you have to define class for every complex type ... please use google to search an examples ... or at least read gson documentation