从文件夹中读取json文件 [英] Reading json file from folder

查看:348
本文介绍了从文件夹中读取json文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码有问题。

错误是:

I have a problem with the code below.
The error is:

"MainPage.ReadJsonFile(String):not all code parts return value"







//JSON starts here
public string ReadJsonFile(string JsonfilePath)
{

    using (StreamReader r = new StreamReader("Dec1.js"))
    {

        string json = r.ReadToEnd();
        dynamic array = JsonConvert.DeserializeObject(json);
        //... read text from json file

       return string text
    }

}

//Daily Devotion starts here
protected override void OnNavigatedTo(NavigationEventArgs e)
{

    AddDevotions();
    int index = DateTime.Now.DayOfYear;
    textblock.Text = devotions[index];
}

List<string> devotions = new List<string>();
private void AddDevotions()
{
    devotions.Add(ReadJsonFile("Assets/Dec1.js"));
    devotions.Add(ReadJsonFile("Assets/Dec2.js"));
    devotions.Add(ReadJsonFile("Assets/Dec3.js"));
    //...for 365 days
}

推荐答案

试试这个:



Try this:

public string ReadJsonFile(string JsonfilePath)
{
    string strText= "";

    using (StreamReader r = new StreamReader("Dec1.js"))
    {

        string json = r.ReadToEnd();
        dynamic array = JsonConvert.DeserializeObject(json);

        //... fill strText
    }

    return strText;

}


这篇关于从文件夹中读取json文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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