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);
}
}
private static final int SPACE_32 = 32;
private static final int SPACE_12288 = 12288;
private static final int SPACE_160 = 160;
private static final int SPACE_8194 = 8194;
private static final int SPACE_8195 = 8195;
private static final int SPACE_8197 = 8197;
private static final int SPACE_8201 = 8201;
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;
}