fastjson对JSONArray解析及用法

package com.example.demo.lz.test;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

/**
 * @author: create by lz
 * @copyright: credlink
 * @date:2020/4/30 11:11
 */
public class Main {
    public static void main(String[] args) {
        String GET_URL_ALL = "[{\"id\":0,\"enterprie_id\":13125,\"enterprie_name\":\"恒丰银行股份有限公司\",\"monitor_title\":\"净利微增!这家股份行终于发了年报,压降千亿不良\",\"monitor_item\":\"舆情信息\",\"monitor_level_id\":1,\"alter_date\":\"2020-05-05\",\"publish_date\":null,\"info_url\":\"http://wap.stcn.com/zqsbapp/yw/202005/t20200503_1738670.html\"},{\"id\":0,\"enterprie_id\":13126,\"enterprie_name\":\"恒丰银行股份有限公司\",\"monitor_title\":\"净利微增!这家股份行终于发了年报,压降千亿不良,股东注册地管理层全翻篇\",\"monitor_item\":\"舆情信息\",\"monitor_level_id\":1,\"alter_date\":\"2020-05-05\",\"publish_date\":null,\"info_url\":\"https://new.qq.com/omn/20200503/20200503A0GDQM00.html\"},{\"id\":0,\"enterprie_id\":13121,\"enterprie_name\":\"招商局蛇口工业区控股股份有限公司\",\"monitor_title\":\"招商蛇口深圳项目恐因“捂盘惜售”被查 192套房源遭“分局锁定”\",\"monitor_item\":\"舆情信息\",\"monitor_level_id\":1,\"alter_date\":\"2020-05-05\",\"publish_date\":null,\"info_url\":\"http://dy.163.com/v2/article/detail/FBK4NIEK0512D03F.html\"}]";
        //String URL_ALL  = "http://syqb.credlink.com/dateSelect";
        try {
            JSONArray objects = JSONArray.parseArray(GET_URL_ALL);
            int size = objects.size();
            for (int i = 0; i < size; i++) {
                JSONObject jsonObject = objects.getJSONObject(i);
                System.out.println(jsonObject.get("monitor_title"));
            }
            System.out.println("=============");
            JSONArray object2 = JSON.parseArray(GET_URL_ALL);
            int size2 = object2.size();
            for (int i = 0; i < size2; i++) {
                JSONObject jsonObject = object2.getJSONObject(i);
                System.out.println(jsonObject.get("monitor_title"));
            }
            System.out.println("1111111111111111111111111111");
            if (object2.size() > 0) {
                String title = object2.getJSONObject(0).getString("monitor_title");
                System.out.println(title);
            }

        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("=======");
        }
    }
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值