JSON 文件的引用有很多,但最常见的一中用法是用作配置文件使用,通过配置外部JSON文件,来实现一定的配置化,增加代码的灵活性,开发中的常见手法!
JSON解析手法
这里将介绍我的三种解析方式,分别时使用Java+fastjson、Scala+fastjson、Python+jsonpath,Let’s go !!!
需求: test.json文件为数据库的配置文件信息,通过传入数据库名和表明快速获取到对应信息!
test.json
{
"clean_info": [
{
"database": "db1",
"table_info": [
{
"table_name": "src_member",
"dwd_table": "db1.dwd_src_member",
"time_fields": "birthday",
"phone_fields": "mobile,phone",
"aes_fields": "name,email",
"md5_fields": "address"
},
{
"table_name": "orderinfo",
"dwd_table": "db1.dwd_orderinfo",
"time_fields": "create_time,confirm_time",
"phone_fields": "mobile",
"aes_fields": "consignee,membercard,email",
"md5_fields": "address"
},
{
"table_name": "src_order",
"dwd_table": "db1.dwd_src_order",
"time_fields": "paytime",
"phone_fields": "mobile"
},
{
"table_name"<