Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse a JSONString To 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.

My JSONString is :

{
    "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"
        }
    ]
}
like image 919
Chirag Parmar Avatar asked Oct 02 '13 11:10

Chirag Parmar


People also ask

How to parse JSON string to Java object using Gson library?

We can parse json string to java object using Gson library. We have one json string like Now we will parse json string to java object , So first we create java pojo with filed name id and name String line = ""; //stores the text to parse. StringTokenizer st = new StringTokenizer (line, ":"); String input1 = st.nextToken ();

How does a JSON parser work?

A JSON parser transforms a JSON text into another representation must accept all texts that conform to the JSON grammar. It may accept non-JSON forms or extensions. An implementation may set the following: set limits on the length and character contents of strings.

How to read and parse JSON and convert to Dataframe in spark?

Assume you have a text file with a JSON data or a CSV file with a JSON string in a column, In order to read these files and parse JSON and convert to DataFrame, we use from_json () function provided in Spark SQL. 1. Read and Parse a JSON from a TEXT file

How do I read a JSON string from a text file?

1. Read and Parse a JSON from a TEXT file In this section, we will see parsing a JSON string from a text file and convert it to Spark DataFrame columns using from_json () Spark SQL built-in function.


1 Answers

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.

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

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

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

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.

like image 133
Oualid KTATA Avatar answered Oct 31 '22 03:10

Oualid KTATA