Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a problem with the code below.
The error is:
"MainPage.ReadJsonFile(String):not all code parts return value"


C#
//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
}
Posted
Updated 16-Jan-15 1:56am
v2

1 solution

Try this:

C#
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;

}
 
Share this answer
 
Comments
Member 10627743 16-Jan-15 8:27am    
Thank you for your reply, when i tried it this is the error it gave

"An exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.ni.dll but was not handled in user code

If there is a handler for this exception, the program may be safely continued."

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