无法从jsonArray访问值

时间:2012-11-06 07:01:23

标签: json

我正在使用gson来解析json 我有一个com.google.gson.jsonArray

    JsonObject object = jelement2.getAsJsonObject().getAsJsonObject("fields");   
    JsonArray jArray = (JsonArray) object.get("entity_facets");

    Output of jArray is :
    [{"count":4,"entity":"Com","Company":[{"sector":"Communications","ticker":"VZ","entity":"Verizon","type":"BCap","instance":[{"count":1,"entity":"Verizon (VZ, Fortune 500)"}]},{"sector":"Technology","ticker":"AAPL","entity":"Apple","type":"BCap","instance":[{"count":1,"entity":"Apple (AAPL, Fortune 500)"}]},{"sector":"Communications","ticker":"T","entity":"AT&T","type":"BCap","instance":[{"count":1,"entity":"(T, Fortune 500)"},{"count":1,"entity":"AT&T"}]}]}]

现在我想从jArray

中提取Company下的数组

1 个答案:

答案 0 :(得分:1)

像这样添加

JsonObject jobject = jArray.get(0);
JsonArray CompanyArray = (JsonArray)jobject.getAsJsonArray(Company);

你将从jArray获得公司阵列。