awais
awais

Reputation: 3

Read json file and store it in string UWP C#

Whenever I run my application I get the following exception

An exception of type 'System.InvalidOperationException' occurred in System.IO.FileSystem.dll but was not handled in user code

Synchronous operations should not be performed on the UI thread. Consider wrapping this method in Task.Run.

string json = File.ReadAllText(@"C:\Users\PC\Documents\Visual Studio 2015\Projects\ApiInUniversal\ApiInUniversal\Assets\stream.json");

How can I parse JSON?

Upvotes: 0

Views: 807

Answers (1)

Eldho
Eldho

Reputation: 8273

public async void ProcessRead()
{
 string filePath = @"temp2.txt";

 if (File.Exists(filePath) == false)
 {
     Debug.WriteLine("file not found: " + filePath);
 }
 else
 {
     try
     {
         string text = await ReadTextAsync(filePath);
         Debug.WriteLine(text);
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.Message);
     }
 }
}

you can look at parsing the json here , here 2

Upvotes: 0

Related Questions