Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have created a json file named as "1.json" using newtonsoft's jsonconvert.serialize method.
1.json contains only an integer value without any object along with it as shown below
"243"
Please help me out how to get this value from json file
Posted

Please refer this

Read+Json+in+c+code+behind[^]

how-to-obtain-values-in-json-in-c[^]

Hope it will help..
 
Share this answer
 
Try This

C#
public DataTable GetDtFromJson(string jsonString)
    {
        try
        {

            var table = JsonConvert.DeserializeObject<DataTable>(jsonString);
            return table;
        }
        catch (Exception ex)
        {
            throw new ArgumentException(ex.Message);
        }
    }


make sure that you have included
C#
using Newtonsoft.Json;
using Newtonsoft;
 
Share this answer
 
v2
try this.. :)

C#
DataSet dsRecognize = new DataSet();
string jsonStringRecognize = "Json String";
XmlDocument xdRecognize = new XmlDocument();
jsonStringRecognize = "{ \"rootNode\": {" + jsonStringRecognize.Trim().TrimStart('{').TrimEnd('}') + "} }";
xdRecognize = (XmlDocument)JsonConvert.DeserializeXmlNode(jsonStringRecognize);

dsRecognize.ReadXml(new XmlNodeReader(xdRecognize));


for more info.. :)

How to Convert JSON String into Dataset using c#[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900