如何将 JSONString 解析为数据集?

How to parse a JSONString To Dataset?(如何将 JSONString 解析为数据集?)
本文介绍了如何将 JSONString 解析为数据集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Web 服务创建 C# 应用程序.在我的 Web 服务中,我使用的是 JSONString 数据.但我无法将此字符串转换为 DataSet.

I am creating a C# Application using Web Services. In my Web Services I'm using a JSONString data. But I'm not able to convert this string into a DataSet.

我的 JSONString 是:

{
    "Table": [
        {
            "DisplayVoucherNumber": "A101239Z",
            "ActualDate": "08/07/2013",
            "AccountName": "shyamal",
            "Pcs": "50",
            "Weight": "500.000"
        }
    ],
    "Table1": [
        {
            "DisplayVoucherNumber": "R101249B",
            "ActualDate": "11/07/2013",
            "AccountName": "vipul",
            "NetWeight": "90.000",
            "Weight": "80.000",
            "Difference": "10.000"
        },
        {
            "DisplayVoucherNumber": "R101249B",
            "ActualDate": "11/07/2013",
            "AccountName": "vipul",
            "NetWeight": "500.000",
            "Weight": "100.000",
            "Difference": "400.000"
        }
    ]
}

推荐答案

你的问题不是很清楚.我想您想要做的是取回一个可以在反序列化后映射到您的数据集的对象.类似的东西

Your question is not very clear. I guess that what you would like to do is get back an object that could be mapped to you data set after deserializtion. Something like

DataSet myDataSet= JsonConvert.DeserializeObject<DataSet>(jsonstring)

然后你继续用你的数据集进行编码.就像访问数据集中的数据表一样.

And you keep going coding with you dataset. like accessing datatables inside the dataset.

如果这是您想要实现的目标,并且不想按照先前答案的建议使用您自己的 POCO.您可能需要先创建一个 Typed DataSet

If it's what you want to achieve and don't want to use your own POCO as suggested by previous answers. You might need to create a Typed DataSet before

给定一个符合 XML 架构定义语言 (XSD) 标准的 XML 架构,您可以使用随 Windows 软件开发工具包 (SDK) 提供的 XSD.exe 工具生成强类型数据集.更多关于强类型数据集的信息

Given an XML Schema that complies with the XML Schema definition language (XSD) standard, you can generate a strongly typed DataSet using the XSD.exe tool provided with the Windows Software Development Kit (SDK). More info on strongly typed Dataset

这将允许您使用 Deserialize 方法使用强类型数据集.

This will allow you to use the strongly typed dataset using the Deserialize method.

请记住,您必须在 XML 模式中模仿您的 JSON 结构.为了在最后有一些与你的 JSON 结构兼容的东西.

Bare in mind that you have to mimic your JSon Structure in the XML Schema. in order to have something compatible with your JSon Structure at the end.

这篇关于如何将 JSONString 解析为数据集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)