【问题标题】:Powershell Convertto-json outputPowershell Convertto-json 输出
【发布时间】:2021-12-31 06:23:00
【问题描述】:

我使用 powershell 从 shopify 获取流并将其转换为 json 可读文本。 它工作了几个星期,但现在没有返回相同的数据格式。

$uri = "https://yourshop.myshopify.com/admin/api/2021-10/orders.json?limit=250"
$apikey = ""
$password = ""
$headers = @{"Authorization" = "Basic "+[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($apikey+":"+$password))}
$products = Invoke-RestMethod -Uri $uri -FollowRelLink -contentType "application/json" -Method Get -Header $headers -Body $Body -MaximumFollowRelLink 5 
$products | ConvertTo-Json -Depth 5 | Out-File C:\json\ordersdepth5.json -encoding utf8
 

它曾经返回整洁的 json

{
    "orders":  [
                   {
                       "id":  4059713634402,
                       "admin_graphql_api_id":  "gid://shopify/Order/4059713634402",
                       "app_id":  580111,
                       "browser_ip":  "120.154.83.138",
                       "buyer_accepts_marketing":  true,
                       "cancel_reason":  null,
                       "cancelled_at":  null,


但现在它返回了 ["{\"orders\":[{\"id\":4122462257250,\"admin_graphql_api_id\":\"gid:\\/\\/shopify\\/Order\\/4122462257250\",\" 一堆斜线和垃圾

数据流有问题吗?我应该看什么。

除非有 api 更改,否则 Shopify 不会更改格式?

【问题讨论】:

    标签: json powershell


    【解决方案1】:

    我通过将数据移动到 powershell 中进行转换然后再转换为 json 来解决此问题。

    $products | ConvertFrom-Json -AsHashtable | ConvertTo-Json -Depth 5 -Compress |Out-File C:\json\ordersdepth2.json -encoding utf8
    

    【讨论】:

      猜你喜欢
      • 2013-03-12
      • 2021-09-04
      • 2018-08-18
      • 1970-01-01
      • 2015-03-20
      • 2015-05-25
      • 2018-02-12
      相关资源
      最近更新 更多