如何在asp.net c#中的json文件中获取数据 [英] how to get data present in a json file in asp.net c#

查看:745
本文介绍了如何在asp.net c#中的json文件中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用newtonsoft的jsonconvert.serialize方法创建了一个名为1.json的json文件。

1.json只包含一个没有任何对象的整数值,如下所示

243

请帮我解决如何从json文件中获取此值

解决方案

请参考此< br $> b $ b

阅读+ Json + in + c + code + behind [ ^ ]



如何在json-in-c中获取值 [ ^ ]



希望它会有所帮助..


试试这个



  public  DataTable GetDtFromJson( string  jsonString)
{
尝试
{

var table = JsonConvert.DeserializeObject< DataTable>(jsonString);
return 表;
}
catch (例外情况)
{
throw new ArgumentException(ex.Message);
}
}





确保已包含

 使用 Newtonsoft.Json; 
使用 Newtonsoft;


试试这个.. :)



 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));





了解更多信息.. :)



如何使用c#将JSON字符串转换为数据集 [ ^


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

解决方案

Please refer this

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

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

Hope it will help..


Try This

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

using Newtonsoft.Json;
using Newtonsoft;


try this.. :)

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#[^]


这篇关于如何在asp.net c#中的json文件中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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