c# - 匿名数组的Json反序列化

标签 c# .net json datacontractjsonserializer

我想使用 DataContractJsonSerializer 反序列化以下 json:

 "coordinates": [
                           [
                               18.008966033966707,
                               59.328701014313964
                           ],
                           [
                               18.008642062225096,
                               59.3283087435048
                           ]
                       ]

由于数组中的项目没有名称,我不知道如何告诉 DataContractJsonSerializer 这些项目是什么。我尝试过:

[DataContract]
public  class Coordinate :IExtensibleDataObject
{

    [DataMember(Order = 1)]
    public decimal Longitude { get; set; }

    [DataMember(Order = 2)]
    public decimal Latitude { get; set; }

    public ExtensionDataObject ExtensionData { get; set; }
}

有什么想法吗?

最佳答案

了解如何执行此操作。下面的代码解决了这个问题:

[CollectionDataContract] 
public  class Coordinate : List<object> 
{ 
    public decimal Longitude { get { return (decimal)this[0]; } set { this[0] = value; } } 

    public decimal Latitude { get { return (decimal)this[1]; } set { this[1] = value; } } 

    public ExtensionDataObject ExtensionData { get; set; } 
} 

关于c# - 匿名数组的Json反序列化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9748926/

相关文章:

C# 委托(delegate)实例化与仅传递方法引用

c# - 为什么 `IList<T>` 不继承自 `IReadOnlyList<T>` ?

c# - 如何将 "var"用法(而不是显式类型)视为警告?

c# - foreach 上的 if 语句

php - 使用 StringRequest 传递共享首选项值,以便我可以过滤 SQL 查询

java - 找不到 Gson 模块 Blackberry Java 应用程序

C#保护数据库连接信息

c# - 保持鼠标事件从 WindowsFormsHost 冒泡

.net - .Net 中的页面错误和编程

java - Jackson 从值构建 JSON,术语?