在做百度VCR發(fā)票識別中遇到了如下的問題,百度接口返回給我了json格式的字符串,那么毫無疑問我需要進行處理一下。
成都創(chuàng)新互聯(lián)于2013年創(chuàng)立,先為峰峰礦等服務(wù)建站,峰峰礦等地企業(yè),進行企業(yè)商務(wù)咨詢服務(wù)。為峰峰礦企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。返回回來的代碼如下:
{
"words_result_num": 45,
"words_result": {
"CommodityUnit": [
{
"row": "1",
"word": "件"
}
],
"PurchaserAddress": "",
"SheetNum": "",
"CommodityType": [
{
"row": "1",
"word": "DHE-8011耳機"
}
],
"TotalAmount": "34.51",
"Checker": "王燕",
"PurchaserBank": "",
"Agent": "否",
"Password": "645<++0+253*899/4-6--6/1>0>93067755>19/<04025693>*52/83-00-*<<3-*+3181581>>>6824*1>8/63067755>19/<04023>37",
"InvoiceTypeOrg": "江蘇增值稅電子普通發(fā)票",
"InvoiceCodeConfirm": "032002100811",
"TotalTax": "4.49",
"ServiceType": "電器設(shè)備",
"CommodityTaxRate": [
{
"row": "1",
"word": "13%"
}
],
"CommodityTax": [
{
"row": "1",
"word": "4.49"
}
],
"SellerBank": "中國建設(shè)銀行南京徐莊軟件園支行32001881436052508322",
"Remarks": "38214257941",
"SellerAddress": "南京市玄武區(qū)玄武大道699-19號8幢025-66996699",
"NoteDrawer": "劉婭",
"InvoiceTag": "其他",
"InvoiceNumConfirm": "58067464",
"OnlinePay": "",
"Payee": "施怡紅",
"CommodityName": [
{
"row": "1",
"word": "*計算機配套產(chǎn)品*hp/惠普DHE-8011耳機"
}
],
"CommodityVehicleType": [],
"InvoiceCode": "032002100811",
"AmountInWords": "叁拾玖圓整",
"AmountInFiguers": "39.00",
"City": "",
"InvoiceType": "電子普通發(fā)票",
"CommodityEndDate": [],
"PurchaserName": "個人",
"InvoiceDate": "2022年06月20日",
"CommodityNum": [
{
"row": "1",
"word": "1"
}
],
"PurchaserRegisterNum": "",
"MachineCode": "661616292450",
"CommodityPlateNum": [],
"CheckCode": "77221101492528330127",
"SellerRegisterNum": "91320102575938948G",
"CommodityPrice": [
{
"row": "1",
"word": "34.51327434"
}
],
"CommodityStartDate": [],
"SellerName": "南京蘇寧易購電子商務(wù)有限公司",
"CommodityAmount": [
{
"row": "1",
"word": "34.51"
}
],
"Province": "江蘇省",
"InvoiceNum": "58067464"
},
"log_id": 1598565862431452614
}
打印臺出的為:
這邊我寫了一個方法進行處理,這里舉出一個典型的例子以獲取CommodityUnit的row和獲取InvoiceDate時間為例
public static String getHashMapByJson(String jsonResult) {
JSONObject jsonObject = new JSONObject(jsonResult);
//將json格式轉(zhuǎn)化為指定的map集合
Map>>>map=(Map)jsonObject.toMap();
String words_result = map.get("words_result").toString();
String s = map.get("words_result").get("CommodityUnit").get(0).get("row").toString();
Map>map1=(Map)jsonObject.toMap();
//獲取發(fā)票日期
String invTime = map1.get("words_result").get("InvoiceDate");
return invTime;
}
最后在測試段成功獲取
測試端代碼如下,
測試的時間調(diào)用方法調(diào)取方法
String invTime = BaiDuOCR.getHashMapByJson(jsonResult);
System.out.println(invTime);
打印內(nèi)容如下:
測試CommodityUnit的row調(diào)用的方法
String s = BaiDuOCR.getHashMapByJson(jsonResult);
System.out.println(s);
運行成功
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機房具備T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級服務(wù)器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧