Opening files problem windows phone 8

Nov 17, 2013 at 5:08 AM
I am getting a very strange error. Whenever I try to deserialize or use json to linq on text that was read from a file, I get a JSONReaderException Unexpected character encountered while parsing value: . Path '', line 0, position 0. This does not happen when the string was set in the code, even when both are the same.
Nov 17, 2013 at 4:55 PM
jpal wrote:
I am getting a very strange error. Whenever I try to deserialize or use json to linq on text that was read from a file, I get a JSONReaderException Unexpected character encountered while parsing value: . Path '', line 0, position 0. This does not happen when the string was set in the code, even when both are the same.
An encoding problem, perhaps? Can you post the code you're using to read the text from the file?
Nov 17, 2013 at 8:14 PM
public static async Task<JObject> ReadJSON(StorageFile file) {
    var stream = await file.OpenStreamForReadAsync();
    byte[] buffer = new byte[stream.Length];
    stream.Read(buffer, 0, buffer.Length);
    string s = Encoding.UTF8.GetString(buffer, 0, buffer.Length);
    return JObject.Parse(s);
}