Click here to Skip to main content
14,492,143 members
Rate this:
Please Sign up or sign in to vote.
See more:
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
}
Posted
Updated 16-Jan-15 1:56am
v2

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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;

}
   
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100