how do i check JsonObject have nothing android like below format

时间:2018-02-03 10:11:51

标签: android json

{
    "error": false,
    "company_data": [
        {
            "company": {
                "details": [
                    {}
                ],
                "product": [
                    {}
                ]
            }
        }
    ]
}

2 个答案:

答案 0 :(得分:0)

JSONObject object = new JSONObject(jsonString);
if(object.has("error"))

答案 1 :(得分:0)

JSONObject jsonObject = new JSONObject(output);

JsonArray array  = jsonObject.getJsonArray("company_data");

if(array.length()!=0)
{
  for(int i =0;i<array.length;i++)
    {
     JSONObject company = array.getJSONObject("company");

     JSONArray detailArray = company.getJsonArray("details");

       if(detailArray,length()!0)

           {

                //do Something

           }
        else
           {

           //array Empty

            }
      }

}