任何人都可以帮助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 <eabff56c075e40a688404208276b3098>: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 <eabff56c075e40a688404208276b3098>:0
at System.Data.DataSet..ctor (System.Runtime.Serialization.SerializationInfo inf
o, System.Runtime.Serialization.StreamingContext context, System.Boolean ConstructSchema) [0x00069] in <eabff56c075e40a688404208276b3098>:0
at System.Data.DataSet..ctor (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) [0x00000] in <eabff56c075e40a688404208276b3098>: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 <c19705166c7c4a608e182e859c4de6d2>: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 <c19705166c7c4a608e182e859c4de6d2>: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 <c19705166c7c4a608e182e859c4de6d2>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Boolean checkAdditionalContent) [0x000db] in <c19705166c7c4a608e182e859c4de6d2>:0
at Newtonsoft.Json.JsonSerializer.DeserializeInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00053] in <c19705166c7c4a608e182e859c4de6d2>:
0
at Newtonsoft.Json.JsonSerializer.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00000] in <c19705166c7c4a608e182e859c4de6d2>:0
at Newtonsoft.Json.JsonConvert.DeserializeObject (System.String value, System.Type type, Newtonsoft.Json.JsonSerializerSettings settings) [0x0002d] in <c19705166c7c4a608e182e859c4de6d2>:0
at Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in <c19705166c7c4a608e182e859c4de6d2>:0
at Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value) [0x00000] in <c19705166c7c4a608e182e859c4de6d2>:0
缺少什么?我应该添加任何XML架构吗? 提前致谢
答案 0 :(得分:1)
您应该使用“代替”
在https://jsonlint.com中查看您的Json文字 你有一个例外
**"Error: Parse error on line 1:
'Table1': [{ 'id':"**
但如果你这样写的话
{
"Table1": [{
"id": 0
}, {
"id": 1
}]
}
比所有工作都好。