【发布时间】:2019-06-25 19:04:20
【问题描述】:
我在解析 android 中的 JSON 数据时遇到问题。
我的安卓代码
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, server_url,null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray1=response.getJSONArray("employee");
for(int i=0;i<jsonArray1.length();i++)
{
JSONObject employe=jsonArray1.getJSONObject(i);
Log.d(TAG, "onResponse emp: "+employe.getString("name"));
}
}
catch (JSONException e) {
e.printStackTrace();
}
}
}
我的 JSON 数据
{"orgs":[{"id":1551,"employeeId":1501,"orgId":"1151","employeeOrgMembershipStatus":"MEMBER","employeeRole":"SUPER_ADMIN","lMb":"alvin","lMd":"2019-06-01T05:41:00Z"}],"employee":{"id":1501,"employeeStatus":"ACTIVE","userId":"SU9iegDhr3b9r3gCUZzXl9eQjEJ2","name":"Alvin J Babu","cB":"alvin","cD":"2019-06-24T05:41:00Z","lMb":"alvin","lMd":"2019-06-27T05:41:00Z","computedTotalActivityScore":5,"stars":2,"jobTitle":"Developer","visibility":"ORGANIZATION","asset":null,"reportsTo":null},"teams":[{"id":1601,"employeeId":1501,"teamId":"1251","employeeTeamMembershipStatus":"MEMBER","lMb":"alvin","lMd":"2019-06-25T05:41:00Z"}],"status":1}
我需要解析员工数组并从中获取名称。
【问题讨论】:
标签: android json parsing nested android-volley