读取text内容,将json格式转换为map

12 篇文章 0 订阅
8 篇文章 0 订阅

Map<String, Object> result = new HashMap<>();

String url = taskConfig.getJuziLendingReportUrl();

Map<String, String> params = new HashMap<>(1);

params.put("id", id);

String responseBody = read("D:\\2018051401.txt");

result = new Gson().fromJson(responseBody, HashMap.class);

return result;

 

public static String read(String filePath){

File file=new File(filePath);

FileReader fr=null;

BufferedReader br=null;

String content="";

String line=null;

try {

fr=new FileReader(file);

br=new BufferedReader(fr);

while((line=br.readLine())!=null){

content=content+line;

}

} catch (FileNotFoundException e) {

System.out.println("指定的文件不存在:"+file.getName());

e.printStackTrace();

return null;

} catch (IOException e) {

System.out.println("读取文件出错");

e.printStackTrace();

return null;

}finally{

if(br!=null){try {br.close();} catch (IOException e) {e.printStackTrace();}}

if(fr!=null){try{fr.close();}catch(IOException e){e.printStackTrace();}}

}

return content;

}

 

 

 

//没有乱码

public static String read(String filePath) throws IOException{

String str = "";

File file = new File(filePath);

FileReader fr;

try {

fr = new FileReader(file);

BufferedReader br = new BufferedReader(fr);

String nextline="";

while( (nextline=br.readLine()) !=null) {

nextline = new String(nextline.getBytes("UTF-8"),"UTF-8");//将读取出来的GBK格式的代码转换成UTF-8

//因为Eclipse的默认格式是GBK,而我们读到的ftl文件的格式是UTF-8

//当然,实际上要根据实际的情况来进行修正。

str += nextline;

}

} catch (Exception e) {

e.printStackTrace();

}

return str;

}

 

 

 

 

 

 

text内容:

{"bankCard":"","grantDetail":{"antifraud":{"申请欺诈评分:申请欺诈评分:(80,+)":0.0,"三要素验证:验证结果:0":0.0,"欺诈信息验证:欺诈验证代码:电话号码与本人匹配,30内有使用":0.0,"黑产:黑产分数:[0,20)":0.0},"granting":{"BairongCreditGrant:ZmCreditScore:zmScore:[680,750)":213.0,"BairongCreditGrant:BairongLabel:wlLimit:A":353.0,"BairongCreditGrant:BdMultiBorrow:multiCount:null":433.0,"BairongCreditGrant:custCallRecord:weeHourRatio:[8,~)":508.0,"BairongCreditGrant:custCallRecord:effectiveInRatio:[25,35)":595.0,"BairongCreditGrant:custCallRecord:latestMonthCallOfThreeMonthRatio:(~,28)":640.0,"BairongCreditGrant:BairongCreditGrantBean:consumeGrade:[60,100)":704.0,"BairongCreditGrant:BairongLabel:assetLevel:0":718.0,"BairongCreditGrant:BairongLabel:inLevel:D":743.0,"BairongCreditGrant:BairongLabel:outLevel:B":774.0,"BairongCreditGrant:BairongCreditGrantBean:age:null":806.0,"BairongCreditGrant:granting:score:[795,830)":6000.0}},"zmAntifraudScore":{"risk_hit":null,"address":null,"ip":null,"mobile":"18250758652","hasZmAntifraudScore":true,"mac":null,"score":100.0,"name":"高顺达","imei":null,"bankcard":null,"wifimac":null,"email":"18250758652","query_time":"2018-05-13 11:06:19"},"resultCode":0.0,"idNumber":"3****************8","score":806.0,"rateType":"RAT02","tcBankcard":{"hasTcBankcardInfo":false},"rate":36.0,"applyserialno":"20180513110616289cfa09ccbe9545029","tcInsuranceBase":null,"regPhoneNo":"18250758652","bdMultBorrow":{"hasRiskBull":false},"amount":6000.0,"idType":1.0,"dsbShebao":{"hasDashebao":false},"changeReason":"百融用户授信成功。","tcMobidleConsumeInfo":{"id":115.0,"reqid":"2e9018f8-9886-46d0-a3d3-ff3712c9a679","userid":null,"idNo":"3****************8","mobile":"18250758652","province":"福建","city":"厦门","isp":"移动","gradeSeqNum":"0291526223784656","onlineSeqNum":"0291526223784934","consumeGrade":"02","consumeGradeDesc":"(50,100]","onlineTime":"3","onlineTimeDesc":"(24,+)","queryTime":"2018-05-13 11:06:20"},"rateUnit":"01","bdBlackIndustry":{"hasBlackIndustry":true,"blackIndustryList":[{"id":null,"reqid":"2e9018f8-9886-46d0-a3d3-ff3712c9a679","userid":null,"matchsuccess":"1","score":0.0,"level1blackcount":0.0,"level2blackcount":0.0,"level3blackcount":0.0,"querytime":"2018-05-13 11:06:17"}]},"changeMount":0.0,"userName":"高顺达","grantMsg":"百融用户授信成功。","zmCreditSocre":{"id":null,"reqid":"2e9018f8-9886-46d0-a3d3-ff3712c9a679","transactionId":"20180513110620675fdfe3d7bfc864157a1266c407b269811","bizNo":"ZM201805133000000343800116662325","openId":"268813961834832684695034383","creditScore":"689","queryTime":"2018-05-13 11:06:21"},"grantResult":"授信成功。","bdRisklist":{"hasRiskInfo":false},"phone":"18800000000","createTime":"2018-05-13 11:06:21","whiteList":{"hasWhiteListInfo":false},"antifraudScore":0.0}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值