json 格式化赋值代码块

json 格式化赋值代码块

public static void main(String[] args) {
        String str = "\"billNo\": \"PD2B20210202000003\",\n" +
                "                        \"$state\": \"ADDED\",\n" +
                "                        \"pluCode\": \"10060\",\n" +
                "                        \"pluName\": \"lsj库存测试商品奥利奥\",\n" +
                "                        \"barCode\": \"4806526075691\",\n" +
                "                        \"serialNo\": 1,\n" +
                "                        \"specDesc\": \"\",\n" +
                "                        \"cargoNo\": \"\",\n" +
                "                        \"pluId\": \"1346307101508502074\",\n" +
                "                        \"isGift\": \"0\",\n" +
                "                        \"pack\": \"包\",\n" +
                "                        \"packName\": \"包\",\n" +
                "                        \"packRate\": \"1.0000\",\n" +
                "                        \"disNum\": \"3.0000\",\n" +
                "                        \"disAssPack\": \"\",\n" +
                "                        \"disAssPackChange\": \"1.0000\",\n" +
                "                        \"packetId\": \"1346307101508503098\",\n" +
                "                        \"disAssPacketNum\": \"3.0000\",\n" +
                "                        \"packetNum\": \"1\",\n" +
                "                        \"scatteredNum\": \"2\",\n" +
                "                        \"relDisNum\": \"3.0000\",\n" +
                "                        \"relAssPack\": \"\",\n" +
                "                        \"disExPrice\": \"5.2200\",\n" +
                "                        \"relAssPackChange\": \"1.0000\",\n" +
                "                        \"relAssPacketNum\": \"3.0000\",\n" +
                "                        \"disInPrice\": \"5.9000\",\n" +
                "                        \"priceType\": \"01\",\n" +
                "                        \"rate\": \"0.0000\",\n" +
                "                        \"price\": \"7.9000\",\n" +
                "                        \"purNum\": null,\n" +
                "                        \"purPrice\": \"0.0000\",\n" +
                "                        \"disInTax\": \"17.7000\",\n" +
                "                        \"pluPickupCode\": null,\n" +
                "                        \"salePrice\": \"7.9\",\n" +
                "                        \"reqType\": null,\n" +
                "                        \"disExTax\": \"15.6600\",\n" +
                "                        \"disRtnInTax\": \"0.00000000\",\n" +
                "                        \"sourceOrderNo\": null,\n" +
                "                        \"remark\": null,\n" +
                "                        \"pdtDate\": null,\n" +
                "                        \"expDate\": null,\n" +
                "                        \"period\": 730,\n" +
                "                        \"salTaxesCode\": \"01\",\n" +
                "                        \"giftGenerationMethod\": \"0\",\n" +
                "                        \"assPack\": null,\n" +
                "                        \"assPackChange\": null,\n" +
                "                        \"assPacketNum\": null,\n" +
                "                        \"crossOrdPluId\": null,\n" +
                "                        \"crossOrdSerialNo\": null,\n" +
                "                        \"toPreBillDtKeyId\": null,\n" +
                "                        \"unitName\": \"包\"";
        String[] tp = str.split(",");
        for (String temp : tp) {
            if (temp.startsWith("\n")) {
                temp = temp.substring(1);
            }
            String in[] = trim(temp).split(":");
            String outtemp = "stkOutDisPlu.put(" + trim(in[0]) + "," + trim(in[1]) + ");";
            System.out.println(outtemp);
        }
    }


    /**
     * 普通的英文半角空格Unicode编码
     */
    private static final int SPACE_32 = 32;

    /**
     * 中文全角空格Unicode编码(一个中文宽度)
     */
    private static final int SPACE_12288 = 12288;

    /**
     * 普通的英文半角空格但不换行Unicode编码(==   ==   == no-break space)
     */
    private static final int SPACE_160 = 160;

    /**
     * 半个中文宽度(==   == en空格)
     */
    private static final int SPACE_8194 = 8194;

    /**
     * 一个中文宽度(==   == em空格)
     */
    private static final int SPACE_8195 = 8195;

    /**
     * 四分之一中文宽度(四分之一em空格)
     */
    private static final int SPACE_8197 = 8197;

    /**
     * 窄空格
     */
    private static final int SPACE_8201 = 8201;

    /**
     * 去除字符串前后的空格, 包括半角空格和全角空格(中文)等各种空格, java的string.trim()只能去英文半角空格
     *
     * @param str
     */
    public static String trim(String str) {

        char[] val = str.toCharArray();
        int st = 0;
        int len = val.length;
        while ((st < len) && isSpace(val[st])) {
            st++;
        }
        while ((st < len) && isSpace(val[len - 1])) {
            len--;
        }
        return ((st > 0) || (len < val.length)) ? str.substring(st, len) : str;
    }

    public static boolean isSpace(char aChar) {
        return aChar == SPACE_32 || aChar == SPACE_12288 || aChar == SPACE_160 || aChar == SPACE_8194
                || aChar == SPACE_8195 || aChar == SPACE_8197 || aChar == SPACE_8201;
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值