Instagram JSON导出。用OPENJSON旋转子数组

问题描述 投票:0回答:1

我刚刚从Instragram收到一个扩展名为.json的文件中的我喜欢的数据。

{"media_likes": [["2019-12-10T17:49:02", "feojo"], 
                 ["2019-12-10T14:11:53", "sollylun"],
                 ["2016-02-16T17:05:43", "ser_mart"]], 
"comment_likes":[["2019-11-28T18:05:04", "kerslyrikatel"], 
                 ["2019-11-28T18:05:03", "jakar"],
                 ["2019-12-10T14:11:53", "sollylun"]]}

我可以在值列中返回子数组,但不知道是谁将那些数组转换为'date'和'user'列:

   DECLARE @JSON1 NVARCHAR(MAX)
    SELECT @JSON1 = '{
                     "media_likes": [
                                     ["2019-12-10T17:49:02", "feonaleejones"], 
                                     ["2019-12-10T14:11:53", "sollyluna021"],
                                     ["2016-02-16T17:05:43", "serene_martin"]
                                    ], 
                      "comment_likes":[
                                      ["2019-11-28T18:05:04", "kerstinslyrikatelier"], 
                                      ["2019-11-28T18:05:03", "jan.kart"],
                                      ["2019-12-10T14:11:53", "sollyluna021"]
                                      ]
                      }'

SELECT [key],value 
  FROM OPENJSON(@JSON1,'$.media_likes') 

key value
0   ["2019-12-10T17:49:02", "feonaleejones"]
1   ["2019-12-10T14:11:53", "sollyluna021"]
2   ["2016-02-16T17:05:43", "serene_martin"]

如何旋转两个数组的值?

约翰

json tsql instagram
1个回答
0
投票
select DECLARE @JSON1 NVARCHAR(MAX) SELECT @JSON1 = '{ "media_likes": [ ["2019-12-10T17:49:02", "feonaleejones"], ["2019-12-10T14:11:53", "sollyluna021"], ["2016-02-16T17:05:43", "serene_martin"] ], "comment_likes":[ ["2019-11-28T18:05:04", "kerstinslyrikatelier"], ["2019-11-28T18:05:03", "jan.kart"], ["2019-12-10T14:11:53", "sollyluna021"] ] }' SELECT likedate,userlike FROM OPENJSON(@JSON1,'$.media_likes') WITH ( likedate datetime '$[0]', userlike varchar(128) '$[1]' )
© www.soinside.com 2019 - 2024. All rights reserved.