Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在PowerShell中维护JSON文件中的整数_Json_Powershell - Fatal编程技术网

如何在PowerShell中维护JSON文件中的整数

如何在PowerShell中维护JSON文件中的整数,json,powershell,Json,Powershell,我有一个名为questions.JSON的JSON文件,内容如下: { "0" : { “问题”:“简单地将此问题的‘获取数据’中的数据汇总”, “数据”:“PowerShell很有趣”, “答案”:“PowerShell很有趣” }, "1" : { “问题”:“提交Get数据+5之和。”, “数据”:7, “答复”:13 } } 如果要将其转换为PSCustomObject,请执行以下操作: $a=Get Content-Raw-Path questions.json | ConvertF

我有一个名为
questions.JSON
的JSON文件,内容如下:

{
"0" : {
“问题”:“简单地将此问题的‘获取数据’中的数据汇总”,
“数据”:“PowerShell很有趣”,
“答案”:“PowerShell很有趣”
},
"1" : {
“问题”:“提交Get数据+5之和。”,
“数据”:7,
“答复”:13
}
}
如果要将其转换为PSCustomObject,请执行以下操作:

$a=Get Content-Raw-Path questions.json | ConvertFrom json
它将
($a.1).数据
($a.1).答案
处的整数转换为字符串

PS C:\>$a
0                                                                                                                    1
-                                                                                                                    -
@{Question=简单地将此问题的“Get data”中的数据汇总;data=PowerShell很有趣;Answer=PowerShell很有趣}@{Question=提交Get data+5的总和;D。。。
PS C:\>$a.1
问题数据答案
--------                        ---- ------
提交Get数据的总和+5.7 13
PS C:\>($a.1).Data|gm
TypeName:System.String
名称成员类型定义
----             ----------            ----------
克隆方法System.Object Clone(),System.Object ICLONABLE.Clone()
CompareTo方法int CompareTo(System.Object值)、int CompareTo(字符串strB)、int IComparable.CompareTo(System.Object对象)、int IComparab。。。
Contains方法bool Contains(字符串值)
CopyTo方法void CopyTo(int sourceIndex,char[]destination,int destinationIndex,int count)
EndsWith方法bool EndsWith(字符串值),bool EndsWith(字符串值,System.StringComparison comparisonType),bool EndsWith(字符串值。。。
Equals方法bool Equals(System.Object obj)、bool Equals(字符串值)、bool Equals(字符串值、System.StringComparison comparisonType。。。
GetEnumerator方法System.CharEnumerator GetEnumerator(),System.Collections.IEnumerator IEnumerable.GetEnumerator(),System.Collections.Gener。。。
GetHashCode方法int GetHashCode()
GetType方法类型GetType()
GetTypeCode方法System.TypeCode GetTypeCode(),System.TypeCode IConvertible.GetTypeCode()
IndexOf方法int IndexOf(字符值),int IndexOf(字符值,int startIndex),int IndexOf(字符串值),int IndexOf(字符串值,int。。。
索引方法int IndexOfAny(char[]anyOf),int IndexOfAny(char[]anyOf,int startIndex),int IndexOfAny(char[]anyOf,int startIndex,in。。。
插入方法字符串插入(int startIndex,字符串值)
IsNormalized方法bool IsNormalized(),bool IsNormalized(System.Text.NormalizationForm NormalizationForm)
LastIndexOf方法int LastIndexOf(char值),int LastIndexOf(char值,int startIndex),int LastIndexOf(字符串值),int LastIndexOf(st。。。
LastIndexOfAny方法int-LastIndexOfAny(char[]anyOf),int-LastIndexOfAny(char[]anyOf,int-startIndex),int-LastIndexOfAny(char[]anyOf,int-st。。。
Normalize方法string Normalize(),string Normalize(System.Text.NormalizationForm NormalizationForm)
PadLeft方法字符串PadLeft(int totalWidth),字符串PadLeft(int totalWidth,char paddingChar)
PadRight方法string PadRight(int totalWidth),string PadRight(int totalWidth,char paddingChar)
Remove方法string Remove(int startIndex,int count),string Remove(int startIndex)
Replace方法string Replace(char oldChar,char newChar),string Replace(string oldValue,string newValue)
Split方法string[]Split(Params char[]separator),string[]Split(char[]separator,int count),string[]Split(char[]separator,system。。。
StartsWith方法bool StartsWith(字符串值)、bool StartsWith(字符串值、System.StringComparison comparisonType)、bool StartsWith(strin。。。
子字符串方法字符串子字符串(int startIndex),字符串子字符串(int startIndex,int length)
ToBoolean方法bool IConvertible.ToBoolean(System.IFormatProvider提供程序)
ToByte方法字节IConvertible.ToByte(System.IFormatProvider提供程序)
ToChar方法char IConvertible.ToChar(System.IFormatProvider提供程序)
ToCharArray方法char[]ToCharArray(),char[]ToCharArray(int startIndex,int length)
ToDateTime方法datetime IConvertible.ToDateTime(System.IFormatProvider提供程序)
ToDecimal方法decimal IConvertible.ToDecimal(System.IFormatProvider提供程序)
ToDouble方法双IConvertible.ToDouble(System.IFormatProvider)
ToInt16方法int16 IConvertible.ToInt16(System.IFormatProvider提供程序)
ToInt32方法int IConvertible.ToInt32(System.IFormatProvider提供程序)
ToInt64方法长IConvertible.ToInt64(System.IFormatProvider提供程序)
ToLower方法string ToLower(),string ToLower(文化信息文化)
ToLowerInvariant方法字符串ToLowerInvariant()
ToSByte方法sbyte IConvertible.ToSByte(System.IFormatProvider)
ToSingle方法浮点IConvertible.ToSingle(System.IFormatProvider)
ToString方法string ToString(),string ToString(System.iFormatProvider
$a = Get-Content -Path .\questions.json -Raw | ConvertFrom-Json

($a.0).Data.GetType().FullName
# System.String

($a.0).Answer.GetType().FullName
# System.String

($a.1).Data.GetType().FullName
# System.Int64

($a.1).Answer.GetType().FullName
# System.Int64
$json = @"
    {
        "0" : {
            "Question" : "Simply sumbit the data in 'Get-Data' for this question",
            "Data" : "PowerShell is fun",
            "Answer" : "PowerShell is fun"
        },
        "1" : {
            "Question" : "Submit the sum of Get-Data + 5.",
            "Data" : 7,
            "Answer" : 13
        }
    }
"@

$a = $json | ConvertFrom-Json

($a.0).Data.GetType().FullName
# System.String

($a.0).Answer.GetType().FullName
# System.String

($a.1).Data.GetType().FullName
# System.Int64

($a.1).Answer.GetType().FullName
# System.Int64