Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.NET C中的Pars json文件#_C#_Asp.net_.net_Json_Deserialization - Fatal编程技术网

C# ASP.NET C中的Pars json文件#

C# ASP.NET C中的Pars json文件#,c#,asp.net,.net,json,deserialization,C#,Asp.net,.net,Json,Deserialization,我有一个.json文件,我想对它进行解析,并在页面中显示项目。 我创建了3个类,名为: bultan_详细信息 布尔塔努新酒店 布尔塔努电视台 这是解析它的代码: using (StreamReader r = new StreamReader(filePath)) { var json = r.ReadToEnd(); var result = JsonCon

我有一个.json文件,我想对它进行解析,并在页面中显示项目。 我创建了3个类,名为: bultan_详细信息 布尔塔努新酒店 布尔塔努电视台 这是解析它的代码:

using (StreamReader r = new StreamReader(filePath))
                    {
                        var json = r.ReadToEnd();
                        var result = JsonConvert.DeserializeObject<Bultan>(json);

                        //var bultanDetails = result.Bultan_Details;
                        var news = result.BultanNews;
                        var telegram = result.BultanTelegram;
                        //Response.Write(bultanDetails.bultan_title + "<br/>");
                        foreach (var item in news)
                        {
                            Response.Write(item.description + "<br/><br/><br/>");
                        }
                        foreach (var tl in telegram)
                        {
                            Response.Write(tl.text + "<br/><br/><br/><br/>");
                        }
                    }
使用(StreamReader r=newstreamreader(filePath))
{
var json=r.ReadToEnd();
var result=JsonConvert.DeserializeObject(json);
//var bultanDetails=结果。Bultan_详细信息;
var news=result.bultanews;
var电报=结果。布尔坦电报;
//回复。写(bultanDetails.bultan_title+“
”); foreach(新闻中的变量项) { 响应.写入(item.description+“


”; } foreach(电报中的var tl) { 响应。写入(tl.text+“




”; } }
这是我的布尔坦班

public class Bultan
    {
        public bultan_details Bultan_Details { get; set; }
        public List<Bultan_New> BultanNews { get; set; }
        public List<Bultan_Tele> BultanTelegram { get; set; }
    }
公共类Bultan
{
公共bultan_详细信息bultan_详细信息{get;set;}
公共列表bultanews{get;set;}
公共列表BultanTelegram{get;set;}
}
但我在运行project后出现以下错误:

(例如,{“name”:“value”})以正确反序列化。要修复此错误 将JSON更改为JSON对象(例如{“name”:“value”})或 将反序列化类型更改为数组或实现 收集接口(如ICollection、IList)类似列表,可以 从JSON数组反序列化。还可以添加JsonArrayAttribute 类型,以强制它从JSON数组反序列化。路径 “bultan_详图”,第1行,第19位

这是我的json文件内容:

{
    "bultan_details": [
        {
            "export_url": "http://localhost/api/public",
            "bultan_title": "عنوان اول",
            "bultan_title2": "عنوان دوم",
            "bultan_title3": "عنوان سوم",
            "bultan_title4": "عنوان چهارم",
            "bultan_logo": "logo.jpg",
            "full_date": "بهمن 25، 1395",
            "morning_azan": "05:30",
            "noon_azan": "12:19",
            "sunset_azan": "18:02",
            "sunset": "17:43",
            "sunrise": "06:55"
        }
    ],
    "bultan_news": [
        {
            "id": 83773354,
            "title": "زمان واریز عیدی بازنشستگان فعلا مشخص نیست",
            "uptitle": "",
            "description": "MyContent",
            "source_name": "ایران آنلاین",
            "time": "1395-11-19 09:43:38",
            "copy_count": 20,
            "base_source": "خبرگزاری فارس",
            "news_group": "اخبار سازمان",
            "news_subject": "تست میشود 2323",
            "news_subject2": "امیر,نظر",
            "news_maker": "تست 25",
            "news_orientation": "negative",
            "news_template": "note",
            "notes": "خوب بود",
            "tone": "pro",
            "tools": "quip",
            "labels": "جالب,قشنگ",
            "another_sources": "کلید فارس,بام فارس"
        },
        {
            "id": 83442478,
            "title": "سایت استانی خبرگزاری فارس اردبیل رونمایی شد",
            "uptitle": "",
            "description": "Description",
            "content": "MyContent",
            "source_name": "ارس تبار",
            "time": "1395-11-16 22:01:00",
            "copy_count": 0,
            "base_source": "ارس تبار",
            "news_group": "",
            "news_subject": "",
            "news_subject2": "",
            "news_maker": "",
            "news_orientation": "",
            "news_template": "",
            "notes": "",
            "tone": "",
            "tools": "",
            "labels": "",
            "another_sources": ""
        },
        {
            "id": 83443525,
            "title": "Title",
            "uptitle": "",
            "description": "Description",
            "content": "MyContent",
            "source_name": "خبرگزاری مهر",
            "time": "1395-11-16 22:15:00",
            "copy_count": 1,
            "base_source": "خبرگزاری مهر",
            "news_group": "",
            "news_subject": "",
            "news_subject2": "",
            "news_maker": "",
            "news_orientation": "",
            "news_template": "",
            "notes": "",
            "tone": "",
            "tools": "",
            "labels": "",
            "another_sources": "تابناک کهکیلویه"
        },
        {
            "id": 83443417,
            "title": "Title",
            "uptitle": "",
            "description": "Description",
            "content": "Content",
            "source_name": "خبرگزاری ایرنا",
            "time": "1395-11-16 22:14:43",
            "copy_count": 1,
            "base_source": "خبرگزاری ایرنا",
            "news_group": "",
            "news_subject": "",
            "news_subject2": "",
            "news_maker": "",
            "news_orientation": "",
            "news_template": "",
            "notes": "",
            "tone": "",
            "tools": "",
            "labels": "",
            "another_sources": "خبرگزاری ایرنا"
        }
],
    "bultan_telegram": [
        {
            "id": 3919776484,
            "link": "https://t.me/Besuye_zohour/4977",
            "source_name": "️Your 
bultan_details
is the same array in
json
as
bultan_news
and
bultan_tele
, you have to define it as a collection in dto class too:

public class Bultan
{
    public List<bultan_details> Bultan_Details { get; set; }
    public List<Bultan_New> BultanNews { get; set; }
    public List<Bultan_Tele> BultanTelegram { get; set; }
}
{
“bultan_详细信息”:[
{
“导出url”:http://localhost/api/public",
“布尔坦头衔”:“布尔坦”,
“bultanنu title2”:“bultanنوانوم”,
“bultanنu title3”:“bultanنوانسوم”,
“bultanنu title4”:“bultanنننچهام”,
“bultan_徽标”:“logo.jpg”,
“完整日期”:“第25天第1395天”,
“早上好”:“05:30”,
“noon_azan”:“12:19”,
《日落阿赞》:“18:02”,
《日落》:“17:43”,
“日出”:“06:55”
}
],
“bultan_新闻”:[
{
“id”:83773354,
“头衔”:“头衔”,
“uptitle”:“,
“说明”:“MyContent”,
“来源名称”:“来源名称”,
“时间”:“1395-11-1909:43:38”,
“复制计数”:20,
“基本来源”:“基本来源”,
“新闻集团”:“新闻集团”,
“新闻主题”:“新闻主题”,
“新闻主题2”:“新闻主题2”,
“新闻制作人”:“25”,
“新闻导向”:“负面”,
“新闻模板”:“备注”,
“注”:“注”,
“语气”:“专业”,
“工具”:“妙语”,
“标签”:“标签、标签”,
“另一个来源”:“另一个来源”
},
{
“id”:83442478,
“头衔”:“头衔”,
“uptitle”:“,
“说明”:“说明”,
“内容”:“MyContent”,
“来源名称”:“来源名称”,
“时间”:“1395-11-16 22:01:00”,
“复制计数”:0,
“基准源”:“基准源”,
“新闻组”:“,
“新闻主题”:“,
“新闻主题2”:“,
“新闻制作人”:“,
“新闻导向”:“,
“新闻模板”:“,
“注”:“注”,
“语气”:“,
“工具”:“,
“标签”:“,
“其他来源”:”
},
{
“id”:83443525,
“头衔”:“头衔”,
“uptitle”:“,
“说明”:“说明”,
“内容”:“MyContent”,
“来源名称”:“来源名称”,
“时间”:“1395-11-16 22:15:00”,
“复制计数”:1,
“基本来源”:“基本来源”,
“新闻组”:“,
“新闻主题”:“,
“新闻主题2”:“,
“新闻制作人”:“,
“新闻导向”:“,
“新闻模板”:“,
“注”:“注”,
“语气”:“,
“工具”:“,
“标签”:“,
“另一个来源”:“另一个来源”
},
{
“id”:83443417,
“头衔”:“头衔”,
“uptitle”:“,
“说明”:“说明”,
“内容”:“内容”,
“来源名称”:“来源名称”,
“时间”:“1395-11-16 22:14:43”,
“复制计数”:1,
“基本来源”:“基本来源”,
“新闻组”:“,
“新闻主题”:“,
“新闻主题2”:“,
“新闻制作人”:“,
“新闻导向”:“,
“新闻模板”:“,
“注”:“注”,
“语气”:“,
“工具”:“,
“标签”:“,
“另一个来源”:“另一个来源”
}
],
“布尔塔努电报”:[
{
“id”:3919776484,
“链接”:https://t.me/Besuye_zohour/4977",

“源名称”:️ 您的
bultan_details
bultan_news
bultan_tele
json
中是相同的数组,您还必须将其定义为dto类中的集合:

Bultan data = new Bultan();

var file = Path.Combine(@"FILE PATH");
if (File.Exists(file))
{
    data = JsonConvert.DeserializeObject<Bultan>(File.ReadAllText(file));
}
公共类Bultan
{
公共列表Bultan_详细信息{get;set;}
公共列表bultanews{get;set;}
公理