首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >c#:对DataSet问题的去中心化

c#:对DataSet问题的去中心化
EN

Stack Overflow用户
提问于 2017-09-18 00:22:08
回答 1查看 410关注 0票数 1

有人可以帮助在c#上解析JSON字符串吗?我在这方面是个新手……

我试着复制https://www.newtonsoft.com/json/help/html/DeserializeDataSet.htm的样本

代码语言:javascript
复制
string json = @"{
            'Table1': [
                  {
                   'id': 0,
                   'item': 'item 0'
                  },
                  {
                    'id': 1,
                    'item': 'item 1'
                  }
                  ]
                 }";


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

我收到异常:

代码语言:javascript
复制
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模式吗?提前感谢

EN

回答 1

Stack Overflow用户

发布于 2017-09-18 04:48:40

你应该用“ '”代替

https://jsonlint.com中检查您的Json文本,您会有一个异常,例如

代码语言:javascript
复制
**"Error: Parse error on line 1:
'Table1': [{        'id':"**

但是如果你这样写的话

代码语言:javascript
复制
{
    "Table1": [{
        "id": 0
    }, {
        "id": 1
    }]
}

而不是一切都能正常工作。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46269044

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档