集算器解析动态JSON入库ITeye - 乐橙lc8

集算器解析动态JSON入库ITeye

2019-01-11 00:27:38 | 作者: 寄风 | 标签: 解析,特点,内容 | 浏览: 2520

  来历: 。

  体系收集的JSON格局数据(s.json)如下:

  {

    “SUCCESS”: [

        {

            "MESSAGE": "IMEI Service List",

            "LIST": {

                "MOVISTAR SPAIN": {

                    "GROUPNAME": "MOVISTAR SPAIN",

                    "SERVICES": {

                        "3": {

                            "SERVICEID": 32,

                            "SERVICENAME": "MOVISTAR NOKIA INSTANTE",

                            "CREDIT": 4,

                            "TIME": "1-30 Minutes",

                            "INFO": " p "text-align: center;\" …… /p ",

                            "Requires.Network": "None",

                            "Requires.Mobile": "None",

                            "Requires.Provider": "None",

                            "Requires.PIN": "None",

                            "Requires.KBH": "None",

                            "Requires.MEP": "None",

                            "Requires.PRD": "None",

                            "Requires.Type": "None",

                            "Requires.Locks": "None",

                            "Requires.Reference": "None"

                        },

                        "8": {

                            "SERVICEID": 77,

                            "SERVICENAME": "MOVISTAR NOKIA 20 NCK",

                            "CREDIT": 12,

                            "TIME": "1-30 Minutes",

                            "INFO": " p "text-align: center;\" …… /p ",

                            "Requires.Network": "None",

                            "Requires.Mobile": "None",

                            "Requires.Provider": "None",

                            "Requires.PIN": "None",

                            "Requires.KBH": "None",

                            "Requires.MEP": "None",

                            "Requires.PRD": "None",

                            "Requires.Type": "None",

                            "Requires.Locks": "None",

                            "Requires.Reference": "None"

                        }

                    }

                },

                "VODAFONE SPAIN": {

                    "GROUPNAME": "VODAFONE SPAIN",

                    "SERVICES": {

                        "5": {

                            "SERVICEID": 50,

                            "SERVICENAME": "VODAFONE NOKIA BB5 SL3",

                            "CREDIT": 5,

                            "TIME": "1-60 Minutes",

                            "INFO": " p "text-align: center;\" …… /p ",

                            "Requires.Network": "None",

                            "Requires.Mobile": "None",

                            "Requires.Provider": "None",

                            "Requires.PIN": "None",

                            "Requires.KBH": "None",

                            "Requires.MEP": "None",

                            "Requires.PRD": "None",

                            "Requires.Type": "None",

                            "Requires.Locks": "None",

                            "Requires.Reference": "None"

                        },

                        "10": {

                            "SERVICEID": 95,

                            "SERVICENAME": "VODAFONE SONY SONY ERIC(RAPIDO)",

                            "CREDIT": 16,

                            "TIME": "1-24 Hours",

                            "INFO": " p "text-align: center;\" …… /p ",

                            "Requires.Network": "None",

                            "Requires.Mobile": "None",

                            "Requires.Provider": "None",

                            "Requires.PIN": "None",

                            "Requires.KBH": "None",

                            "Requires.MEP": "None",

                            "Requires.PRD": "None",

                            "Requires.Type": "None",

                            "Requires.Locks": "None",

                            "Requires.Reference": "None"

                        }

                    }

                }

            }

        }

    ],

    “apiversion”: “2.0.0″

}

  现需求依照JSON数据内容,将相应节点下的特点值更新到数据库的对应表中,需求更新的2张表如下:

Create table [dbo].[Groups]

(

  [ID] [int] IDENTITY(1,1) NOT NULL,                   –id

  [Groupname] [nvarchar] (50) not null default(”),    –称号

  [groupid] [int] not null default(0),

 CONSTRAINT [PK_Groups_id] PRIMARY KEY CLUSTERED

(

    [id] ASC

)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

) ON [PRIMARY]

 

CREATE TABLE [dbo].[Services](

  [id]    [int] IDENTITY(1,1) NOT NULL,                             –id

  [Serviceid] [int] not null default(0),           

  [Servicename] [nvarchar] (50) not null default(”),   

  [groupid] [int] not null default(0),                

  [Credit] [decimal] not null default(0.00),

  [Time] [nvarchar] (50) not null default(”),

  [INFO] [nvarchar] (3000) not null default(”),

  [Network] [nvarchar] (100) not null default(‘none’),

  [Mobile] [nvarchar] (100) not null default(‘none’),

  [Provider] [nvarchar] (100) not null default(‘none’),

  [PIN] [nvarchar] (100) not null default(‘none’),

  [KBH] [nvarchar] (100) not null default(‘none’),

  [MEP] [nvarchar] (100) not null default(‘none’),

  [PRD] [nvarchar] (100) not null default(‘none’),

  [Type] [nvarchar] (100) not null default(‘none’),

  [Locks] [nvarchar] (100) not null default(‘none’),

  [Reference] [nvarchar] (100) not null default(‘none’),

  [isstatus] [nvarchar] (1) not null default(’0′),

  [remark] [nvarchar] (255) not null default(”),

  [Pricingid] [int] not null default(0),

 CONSTRAINT [PK_Services_id] PRIMARY KEY CLUSTERED

(

    [id] ASC

)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

) ON [PRIMARY]

 

  其间SERVICES下特点名即为groupid,如3,5,8,10,剩下字段与特点名一一对应。因为LIST和SERVICES下的特点名不固定,给解析带来了难度。差异于一般高档言语,集算器支撑动态数据结构和调集运算,完成并不困难,脚本如下:



 

   A1:以字符串读入JSON文件内容,并运用import@j()将字符串转为行列式带有层次的序表。



 

   A2-A3:依据两个方针表,创立空序表,用于存储解析成果后一次更新到数据库。

  A4-B4:循环序表,在B4中核算LIST下节点数量。

  B5-C6:循环获取LIST节点内容,并在C6中核算SERVICES下节点数量。



 

   C7-D8:循环获取SERVICES节点下特点名和特点值。



 

    D9-D10:将解析后成果别离写回到A2A3中的空序表中。



 

   A11:以groupid为主键,将A2内容更新到groups表中。



 

   A12:以Serviceid为主键,将A3内容更新到services表中。



 

版权声明
本文来源于网络,版权归原作者所有,其内容与观点不代表乐橙lc8立场。转载文章仅为传播更有价值的信息,如采编人员采编有误或者版权原因,请与我们联系,我们核实后立即修改或删除。

猜您喜欢的文章