如何将JSONString解析为数据集? [英] How to parse a JSONString To Dataset?

查看:95
本文介绍了如何将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。
您可能需要在之前创建类型数据集

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 Schema定义语言(XSD)的XML Schema。标准,您可以使用Windows软件开发工具包(SDK)附带的XSD.exe工具生成强类型的数据集。
有关强类型数据集的详细信息

这将允许您使用反序列化方法使用强类型数据集。

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

请注意,您必须在XML模式中模仿JSon结构。
,以便最终与您的JSon Structure兼容。

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解析为数据集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆