alibaba JSON用法示例

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/XUEER88888888888888/article/details/86532885
/**
 * FileName: wxController
 * Author: wangxue
 */


package com.zlhj.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zlhj.dao.NcrIdentity;
import com.zlhj.dao.NcrSpouse;
import com.zlhj.util.AFRuleEnginePolicy;
import org.apache.commons.lang.StringEscapeUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

public class wxController {


    public static void main(String[] args) {

        String date = "";
        AFRuleEnginePolicy AFRuleEnginePolicyScore = new AFRuleEnginePolicy();
        date = AFRuleEnginePolicyScore.ReaderjsonAll("C:\\Users\\wangxue\\Desktop\\baogao\\张东.txt");

        //将所有的字符型json数据转为JsonObject
        JSONObject allJsonObject = JSON.parseObject(date.toString());
        //提取对象类型的
        JSONObject messageHeader = allJsonObject.getJSONObject("messageHeader");
        //直接取JSONObject里的值
        String reportCreateTime = messageHeader.getString("reportCreateTime");
        //提取数组类型的JSON对象
        JSONArray awardCreditInfo = allJsonObject.getJSONArray("awardCreditInfo");

       /* 转为对应的实体类
        NcrIdentity ncrIdentity = NCR_identityObject.toJavaObject(NcrIdentity.class);*/

       //放入json会转为带 / 的形式
        String s = JSON.toJSONString(date);
        System.out.println(s);

        //去掉json中的转译字符 /
        String tmp = StringEscapeUtils.unescapeJavaScript(s);
        System.out.println(tmp);







    }



}

猜你喜欢

转载自blog.csdn.net/XUEER88888888888888/article/details/86532885