使用Java

时间:2018-10-04 06:05:08

标签: java json

嗨,我有这个复杂的Json对象,我正在尝试访问父对象中的某些对象,这就是从控制台打印出来的方式。我能够获取父对象/源对象中的值,但是我还需要访问customerLog。我正在使用javax.Json包,这是我的代码的片段。任何帮助将不胜感激。

public ArrayList<CustomerLog> getCustomers(String jsonString)
    {

        Reader stringReader = new StringReader(jsonString);
        JsonReader reader = Json.createReader(stringReader);
        JsonObject jsonObject = reader.readObject();
        reader.close();

        JsonArray jsonArray = jsonObject.getJsonArray("Customer");

        for(int i = 0; i < jsonArray.size()-5; i++)
        {
            System.out.println(jsonArray.getJsonObject(i).get("ID").toString());
            System.out.println(jsonArray.getJsonObject(i+1).get("Username").toString());
            System.out.println(jsonArray.getJsonObject(i+2).get("EmailAddress").toString());
            System.out.println(jsonArray.getJsonObject(i+4).get("CustomerLogs").toString());
            System.out.println(" ");
        } 
    return null;
    }

响应:

“ 7668” “ YASSIT” “ accounts@ausjetinks.com.au” {“ CustomerLog”:[{“ Notes”:“通过电子邮件发送给Debbie,以了解她的生意如何。”,“ LastContactedUTC”:“ 2015-08-21 06:44:31”,“ FollowUpType”:“”,“状态“:”已完成“,”分配给“:”斯蒂芬·莱格“,”最后联系“:” 2015-08-21 16:44:31“,”最后联系本地“:” 2015-08-21 16:44:31“, “ Customer”:[“ Debbie Radchenko”],“ DateRequiredFollowUp”:“ 2015-09-18”,“ LogID”:“ 36195”},{“ Notes”:“ Debbie回答说,他们的暑假总是在学校里安静吗假期,但她希望事情会在9月回升。“,” LastContactedUTC“:” 2015-08-24 02:05:47“,” FollowUpType“:”“,”状态“:”已完成“,”分配给“:” Stephen Legge“,” LastContacted“:” 2015-08-24 12:05:47“,” LastContactedLocal“:” 2015-08-24 12:05:47“,” Customer“:[” Debbie Radchenko“],” DateRequiredFollowUp“:” 0000-00-00“,” LogID“:” 36197“},{” Notes“:” Will recontact @月末“,” LastContactedUTC“:” 2015-09-18 01:54: 41“,” FollowUpType“:”“,”状态“:”已完成“,”分配给“:”斯蒂芬·莱格“,”最后联系“:” 2015-09-18 11:54:41“,”最后联系本地“:” 2015 -09-18 11:54:4 1“,” Customer“:[” Debbie Radchenko“],” DateRequiredFollowUp“:” 2015-09-30“,” LogID“:” 36538“},{” Notes“:”发送Debbie电子邮件“,” LastContactedUTC“: “ 2015-09-30 06:07:40”,“ FollowUpType”:“”,“状态”:“已完成”,“分配给”:“斯蒂芬·列格”,“最后联系”:“” 2015-09-30 16:07 :40“,” LastContactedLocal“:” 2015-09-30 16:07:40“,” Customer“:[” Debbie Radchenko“],” DateRequiredFollowUp“:” 2015-10-23“,” LogID“:” 36735 “},{” Notes“:”已发送Debbie电子邮件,回复说她下周要下订单“,” LastContactedUTC“:” 2017-01-12 02:25:45“,” FollowUpType“:”“, “状态”:“已完成”,“分配给”:“斯蒂芬·莱格”,“最后联系”:“ 2017-01-12 12:25:45”,“最后联系本地”:“ 2017-01-12 12:25:45” ,“ Customer”:[“ Debbie Radchenko”],“ DateRequiredFollowUp”:“ 2017-01-19”,“ LogID”:“ 39609”},{“ Notes”:“再次通过电子邮件发送给Debbie看看情况如何。”, “ LastContactedUTC”:“ 2017-02-07 01:45:06”,“ FollowUpType”:“”,“ Status”:“ Completed”,“ AllocatedTo”:“ Stephen Legge”,“ LastContacted”:“ 2017-02- 07 11:45:06“,” LastContactedLocal“:” 2017-02-07 11:45:06“,”客户”:[[Debbie Radchenko”],“ DateRequiredFollowUp”:“ 2017-03-07”,“ LogID”:“ 39809”},{“ Notes”:“再次通过电子邮件发送给Debbie,以查看是否已准备好下订单( ....但是我们在很多剪辑上都不够:-(“,” LastContactedUTC“:” 2017-03-07 02:12:00“,” FollowUpType“:”“,” Status“:” Completed“ ,“ AllocatedTo”:“ Stephen Legge”,“ LastContacted”:“ 2017-03-07 12:12:00”,“ LastContactedLocal”:“ 2017-03-07 12:12:00”,“客户”:[“ Debbie Radchenko“],” DateRequiredFollowUp“:” 2017-04-11“,” LogID“:” 40168“},{” Notes“:” Debbie通过电子邮件请求重新激活帐户:通过电子邮件将“帐户申请表”发送给她。 “,” LastContactedUTC“:” 2018-04-23 23:15:32“,” FollowUpType“:”“,” Status“:” Completed“,” AllocatedTo“:” Stephen Legge“,” LastContacted“:” 2018- 04-24-24:09:15:32“,” LastContactedLocal“:” 2018-04-24 09:15:32“,”客户“:[”黛比·拉琴科“],” DateRequiredFollowUp“:” 2018-05-15“, “ LogID”:“ 43219”},{“ Notes”:“黛比返回已完成的应用程序。形式-转发给Trudi“,” LastContactedUTC“:” 2018-04-24 05:06:34“,” FollowUpType“:”“,” Status“:” Completed“,” AllocatedTo“:” Stephen Legge“,” LastContacted “:” 2018-04-24 15:06:34“,” LastContactedLocal“:” 2018-04-24 15:06:34“,”客户“:[”黛比·拉琴科“],” DateRequiredFollowUp“:” 0000- 00-00“,” LogID“:” 43222“},{”注释“:”新帐户申请已填写并使用加拿大驾驶执照签名-发票上应有“,” LastContactedUTC“:” 2018-04-26 03: 27:52“,” FollowUpType“:”帐户“,”状态“:”已完成“,”分配给“:” Trudi Berquist“,”最后联系“:”“ 2018-04-26 13:27:52”,“最后联系本地” ::“ 2018-04-26 13:27:52”,“客户”:[“黛比·拉德琴科”],“ DateRequiredFollowUp”:“ 0000-00-00”,“ LogID”:“ 43226”},{“注释” :“”已联系Debbie re:订购(所有产品现已有货)“,” LastContactedUTC“:” 2018-05-15 00:57:42“,” FollowUpType“:”“,”状态“:”需要重新联系“,” AllocatedTo“:” Stephen Legge“,” LastContacted“:” 2018-05-15 10:57:42“,” LastContactedLocal“:” 2018-05-15 10:57:42“,” Customer“:[[Debbie Radchenko “],” DateR equiredFollowUp“:” 2018-05-22“,” LogID“:” 43274“}]}

0 个答案:

没有答案