PowerShell形成格式正确的json以进行日历输入 [英] PowerShell to form correctly formatted json for calendar entry

查看:190
本文介绍了PowerShell形成格式正确的json以进行日历输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力让PowerShell在创建新的Google日历条目时形成格式正确的json条目.

I am struggling to get PowerShell to form a correctly formatted json entry when creating a new Google Calendar entry.

GC接受的正确配置的json如下:

A correctly configured json, that is accepted by GC is as follows:

'{"end": {"dateTime": "2017-06-07T15:00:00Z"},
 "start": {"dateTime": "2017-06-07T10:00:00Z"}
}'

但是,从哈希表形成json(以便我可以使用变量dateTime)不能正确地形成它,例如:

However, forming a json from a hashtable (so I can use a variable dateTime) does not form it correctly, example:

$body=@{
    start="2017-06-08T10:00:00Z"
    end="2017-06-08T12:00:00Z"}

$json = $body | ConvertTo-Json

$ json返回如下:

$json is returned as follows:

{
    "start":  "2017-06-08T10:00:00Z",
    "end":  "2017-06-08T12:00:00Z"
}

Google Cal API不接受此方法,在使用OAuth 2.0 Playground进行测试时,它会返回以下错误:

This is not accepted by the Google Cal API, an when testing with the OAuth 2.0 Playground it returns the following error:

{
  "error": {
    "code": 400, 
    "message": "Missing end time.", 
    "errors": [
     {
        "domain": "global", 
        "message": "Missing end time.", 
        "reason": "required"
     }
   ]
 }

关于如何使用PowerShell形成格式正确的开始日期和结束日期的任何想法?

Any ideas on how to use PowerShell to form a correctly formatted Start and End date?

谢谢:)

推荐答案

使用嵌套:

$body=@{
 start=@{"datetime" = "2017-06-08T10:00:00Z"}
 end=@{"datetime" = "2017-06-08T12:00:00Z"}} | ConvertTo-Json

输出:

{
    "start":  {
                  "datetime":  "2017-06-08T10:00:00Z"
              },
    "end":  {
                "datetime":  "2017-06-08T12:00:00Z"
            }
}

这篇关于PowerShell形成格式正确的json以进行日历输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆