拆分json格式陣列

2022-05-13 18:48:10 字數 4140 閱讀 4712

把轉換成

);declare my_cursor cursor --定義游標

for (select [key] from airportdemo ) --把資料集匯入游標

open my_cursor --開啟游標

fetch next

from my_cursor into @key --把游標中第一條放到變數key中

while @@fetch_status=0 --迴圈遍歷

begin

select @code='',@countrycn='',@countryus='',@countrycn='',@provincecn='',@provinceus='',@citycn='',@cityus='',@cityid='';--初始化變數

select @data = data from airportdemo where [key]=@key;

print @data ;

select @code = [key] from dbo.gf_stringsplit(@data);--根據data獲得key,data資料表,並把key賦給@code;

select @str = data from dbo.gf_stringsplit(@data);--@str獲得data資料

declare @firstdata nvarchar(

1000

);

select @firstdata= [string] from dbo.uf_strsplit(@str,'

,') where str_id = 1

; declare @seconddata nvarchar(

1000

);

select @seconddata= [string] from dbo.uf_strsplit(@str,'

,') where str_id = 2;--把data按 ,分割開來

declare @thirddata nvarchar(

1000

);

select @thirddata =[string] from dbo.uf_strsplit(@str,'

,') where str_id = 3

; declare @thirdcount

int;

set @thirdcount = dbo.get_strarraylength(@thirddata,'|'

); declare @count

int;

set @count = dbo.get_strarraylength(@seconddata,'|'

);

if(@count = 4

) begin

select @countrycn= [string] from dbo.uf_strsplit(@str,'

,') where str_id = 3

;

select @countryus = [string] from dbo.uf_strsplit(@seconddata,'

|') where str_id = 1;--把 china|阿里(ngq)|97 阿里按'|'

來分割 ,取下標為1的資料

set @cityus=substring(@firstdata,2,len(@firstdata)-1

);

select @cityid = [string] from dbo.uf_strsplit(@seconddata,'

|') where str_id = 3

;

select @citycn = [string] from dbo.uf_strsplit(@seconddata,'

|') where str_id = 4

;

endelse

if(@thirdcount=4

) begin

select @countrycn= [string] from dbo.uf_strsplit(@str,'

,') where str_id=4

;

select @countryus = [string] from dbo.uf_strsplit(@thirddata,'

|') where str_id = 1

;

select @cityid = [string] from dbo.uf_strsplit(@thirddata,'

|') where str_id = 3

;

select @cityus = substring(@firstdata,2,len(@firstdata)-1

);

select @citycn = [string] from dbo.uf_strsplit(@thirddata,'

|') where str_id = 4

;

select @provincecn = [string] from dbo.uf_strsplit(@str,'

,') where str_id=5

;

select @provinceus = [string] from dbo.uf_strsplit(@str,'

,') where str_id=2

; end

else

begin

select @cityid=[string] from dbo.uf_strsplit(@firstdata,'

|') where str_id = 3

;

select @citycn=[string] from dbo.uf_strsplit(@firstdata,'

|') where str_id = 4

;

select @countryus=[string] from dbo.uf_strsplit(@firstdata,'

|') where str_id = 1

; end

insert into dbo.turnairport(code, countrycn, countryus, provincecn, provinceus, citycn, cityus, cityid) values(@code, @countrycn, @countryus, @provincecn, @provinceus, @citycn, @cityus, @cityid);--把資料插入資料表

fetch next

from

my_cursor into @key;

endclose my_cursor --關閉游標

deallocate my_cursor --刪除游標

json 文件拆分工具 JSON 資料拆分

這是在資料提交時遇到的問題。我準備的資料結構是這樣的 path test clients client 1.2.2.2 1.1.1.1 access type 2,name test 01 client 1.2.2.4 1.1.1.4 access type 1,name test 02 clien...

json 格式轉換

datarow 轉換成json格式 public static string tojson datarow drrights jsonbuilder.remove jsonbuilder.length 1,1 jsonbuilder.remove jsonbuilder.length 1,1 ret...

JSON格式介紹

三大分類 1.object格式 簡單格式 物件是乙個無序的 名稱 值 對 集合。乙個物件以 右括號 結束。每個 名稱 後跟乙個 冒號 名稱 值 對 之間使用 逗號 分隔。例子 簡單寫法 key和數字可以不加 號,例子 2.arry格式 簡單格式 陣列是值 value 的有序集合。乙個陣列以 左中括號...