3

I am serializing a C# object with the following code:

            var serializer = new JavaScriptSerializer();
            var serializedResult = serializer.Serialize(rawFile);
            Console.WriteLine(serializedResult);
            return;

Tried serialization with Target Frameworks from 4.5 up to 4.6.1.

Then I am trying deserialize it into R:

     > x <-  read_json("C:\\dump.txt")
     Error in parse_con(txt, bigint_as_char) : 
     lexical error: invalid bytes in UTF8 string.
             ": "Sample pickup:\nVolume [æl]         :     1.00\nFlow [æl
                        (right here) ------^

I am guessing that these are a micro liter. How to best handle these special characters?

Thank you.

witek
  • 984
  • 1
  • 8
  • 25

1 Answers1

0

The crucial hint was from Sergey "If you output it to console, well... it can be broken."

Using File.WriteAllText solves the problem:

            JavaScriptSerializer serializer = new JavaScriptSerializer();
            string serializedResult = serializer.Serialize(rawFile);
            // byte[] bytes = Encoding.Default.GetBytes(serializedResult);
            // string myString = Encoding.UTF8.GetString(bytes);
            File.WriteAllText("dump2.txt", serializedResult);
witek
  • 984
  • 1
  • 8
  • 25