gpt4 book ai didi

时间:: Deserealization to DataSet

转载 作者:太空宇宙 更新时间:2023-11-03 15:00:48 25 4
gpt4 key购买 nike

任何人都可以帮助在 C# 上解析 JSON 字符串吗?

我尝试重现 https://www.newtonsoft.com/json/help/html/DeserializeDataSet.htm 中的示例

string json = @"{
'Table1': [
{
'id': 0,
'item': 'item 0'
},
{
'id': 1,
'item': 'item 1'
}
]
}";

dataSet = JsonConvert.DeserializeObject<DataSet>(json);

我收到异常:

JsonConvert.DeserializeObject exception System.Runtime.Serialization.SerializationException: Member 'XmlSchema' was not found. 09-17 07:41:27.075 I/mono-stdout( 3691): JsonConvert.DeserializeObject exception System.Runtime.Serialization.SerializationException: Member 'XmlSchema' was not found. at System.Runtime.Serialization.SerializationInfo.GetElement (System.String name, System.Type& foundType) [0x00020] in <3fd174ff54b146228c505f23cf75ce71>:0 at System.Runtime.Serialization.SerializationInfo.GetValue (System.String name, System.Type type) [0x0002e] in <3fd174ff54b146228c505f23cf75ce71>:0 at System.Data.DataSet.DeserializeDataSetSchema (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context, System.Data.SerializationFormat remotingFormat, System.Data.SchemaSerializationMode schemaSerializationMode) [0x000f5] in :0 at System.Data.DataSet.DeserializeDataSet (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context, System.Data.SerializationFormat remotingFormat, System.Data.SchemaSerializationMode schemaSerializationMode) [0x00000] in :0 at System.Data.DataSet..ctor (System.Runtime.Serialization.SerializationInfo inf o, System.Runtime.Serialization.StreamingContext context, System.Boolean ConstructSchema) [0x00069] in :0 at System.Data.DataSet..ctor (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) [0x00000] in :0 at (wrapper dynamic-method) System.Object:lambda_method (System.Runtime.CompilerServices.Closure,object[]) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateISerializable (Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonISerializableContract contract, Newtonsoft.Json.Serialization.JsonProperty member, System.String id) [0x0015b] in :0 at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonCo ntainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x00347] in :0 at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x0006d] in :0 at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Boolean checkAdditionalContent) [0x000db] in :0 at Newtonsoft.Json.JsonSerializer.DeserializeInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00053] in : 0 at Newtonsoft.Json.JsonSerializer.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00000] in :0 at Newtonsoft.Json.JsonConvert.DeserializeObject (System.String value, System.Type type, Newtonsoft.Json.JsonSerializerSettings settings) [0x0002d] in :0 at Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in :0

缺少什么?我应该添加任何 XML 架构吗?

最佳答案

正如@Willem 在评论中指出的那样使用双引号(这验证了 here ):

{
"Table1": [{
"id": 0,
"item": "item 0"
},
{
"id": 1,
"item": "item 1"
}
]
}

以下符号图是来自JSON.org的描述 enter image description here

关于时间:: Deserealization to DataSet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46267702/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com