2

I previously asked a question here on SO about this issue, but now I observed that I did not investigate much about the issue, thus I wrongly concluded that the error was in the JSON library I was using (Newtonsoft), as specified in that previous question.

After testing with Microsoft's Web.Script.Serialization and exactly the same issue persists, I thus deem it fit to rather ask it as a separate SO question; so that the question will attract the appropriate audience, with the appropriate title.

Aside from the above clarification, the issue still remains the same as in the last question, with additional details below:

In my c# application. I have the following c# class to serialize:

class sync_object
{
    public Dictionary<string, List<Dictionary<string, string>>> TableRecords { get; set; }
    public Dictionary<string, List<string>> ClassListWithSubjectsOffered { get; set; }
    public Dictionary<string, List<string>> ClassListWithScoreheadsOffered { get; set; }
    public List<string> ClassGroupsOrdered { get; set; }
    public List<string> SessionBoundTableRecords { get; set; }
}

After creating an instance of sync_object and filling it with data, I did serializer.SerializeObject(instance_of_sync_object) (as I mentioned earlier, it does not matter if I used Json.NET or Miscrosoft's Json handler as serializer)

The output of the serialization was then dumped to a temporary file (for this debug):

internal static void writeStringToFile(string file, string content, bool append = false)
{
    using (StreamWriter sr = new StreamWriter(file, append, Encoding.UTF8))
    {
        sr.Write(content);
        sr.Close();
    }
}

On my PC (as well as PCs of other app users), output is fine. On some other PCs (my other app users), output is reversed/garbled. (As an aside, when I serialize some other c# class instances, the serialized Json output on these problematic PCs will have question marks (like: '?????????') in place of Json keys when I dumped the output to Console (even with Console.OutputEncoding = System.Text.Encoding.UTF8;, while being completely perfect on my PCs and those other PCs)

Sample of JSON string dumped to the temp file on my PC and other PCs that showed correct output:

{"TableRecords":{"personal_db":[{"id":"1","pixFile":"","regNo":"CSS/1819/1","custom_school_id":"","house":"","std_name":"ADETUNMBI FUNMLADE","dob":"","pob":"","dateOfAdmission":"","classAdmitted":"BASIC1 OMOTAYO","religion":"","homeTown":"","lga":"","state":"","Nationality":"","parentName":"","parentContact":"0","parentEmail":"","siblings":"","occupation":"","positionInFamily":"","health":"","prevSchool":"","prevClassAtPreviousSchool":"","reasonForLeaving":"","currClass":"BASIC1 OMOTAYO","ssclassif":"","sex":"","dropped":"false","graduated":"false","session_admitted":"2018/2019","session_dropped":"","term_dropped":"0","session_graduated":"","date_graduated":"","sort_group":""},{"id":"2","pixFile":"","regNo":"CSS/1819/2","custom_school_id":"","house":"","std_name":"AJADI DEBORAH","dob":"","pob":"","dateOfAdmission":"","classAdmitted":"BASIC1 OMOTAYO","religion":"","homeTown":"","lga":"","state":"","Nationality":"","parentName":"","parentContact":"0","parentEmail":"","siblings":"","occupation":"","positionInFamily":"","health":"","prevSchool":"","prevClassAtPreviousSchool":"","reasonForLeaving":"","currClass":"BASIC1 OMOTAYO","ssclassif":"","sex":"","dropped":"false","graduated":"false","session_admitted":"2018/2019","session_dropped":"","term_dropped":"0","session_graduated":"","date_graduated":"","sort_group":""}],"staff_records":[],"std_class_session_data":[{"id_sessional":"1","regno_sessional":"CSS/1819/1","session":"2018/2019","class":"BASIC1 OMOTAYO","ssclassif_sessional":"","location":"","date_entered":"3/18/2019 7:49:39 AM"},{"id_sessional":"2","regno_sessional":"CSS/1819/2","session":"2018/2019","class":"BASIC1 OMOTAYO","ssclassif_sessional":"","location":"","date_entered":"3/18/2019 7:49:41 AM"}],"score_headers":[{"id":"17","name":"TEST (100 marks)","max_obtainable_score":"100","class_group":"","display_on_result":"yes","display_on_midterm_report":"no","mapped_score_header":"","is_exam":"","is_display_score_header":"","display_as":"TEST","session":"2018/2019","created_at":"2019-03-18 07:51:48"},{"id":"18","name":"EXAM (100 marks)","max_obtainable_score":"100","class_group":"","display_on_result":"yes","display_on_midterm_report":"no","mapped_score_header":"","is_exam":"","is_display_score_header":"","display_as":"EXAM","session":"2018/2019","created_at":"2019-03-18 07:51:48"}],"scores":[{"id":"1","std_id":"CSS/1819/1","term":"1","session":"2018/2019","std_class":"BASIC1 OMOTAYO","subject":"RELIGION","score_header":"TEST (100 marks)","score":"92","teacher_comment":"","date_created":"2019-03-18 07:51:48","updated_at":"2019-03-18 07:51:48"},{"id":"2","std_id":"CSS/1819/1","term":"1","session":"2018/2019","std_class":"BASIC1 OMOTAYO","subject":"RELIGION","score_header":"EXAM (100 marks)","score":"100","teacher_comment":"","date_created":"2019-03-18 07:51:48","updated_at":"2019-03-18 07:51:48"}]},"ClassListWithSubjectsOffered":{"BASIC1 MBADUGHA":["ART","BASIC SCIENCE","COMPOSITION","COMPUTER","ENGLISH","FRENCH","HEALTH EDUCATION","MATHEMATICS","MUSIC","PHONICS","QUANTITATIVE","READING","RELIGION","SOCIAL STUDIES","SPELLING","VERBAL","VOCATIONAL APTITUDE","YORUBA","ENGLISH","MATHEMATICS"],"BASIC1 OMOTAYO":["ART","BASIC SCIENCE","COMPOSITION","COMPUTER","ENGLISH","FRENCH","HEALTH EDUCATION","MATHEMATICS","MUSIC","PHONICS","QUANTITATIVE","READING","RELIGION","SOCIAL STUDIES","SPELLING","VERBAL","VOCATIONAL APTITUDE","YORUBA","ENGLISH","MATHEMATICS"],"BASIC1 SOGBESAN":["ART","BASIC SCIENCE","COMPOSITION","COMPUTER","ENGLISH","FRENCH","HEALTH EDUCATION","MATHEMATICS","MUSIC","PHONICS","QUANTITATIVE","READING","RELIGION","SOCIAL STUDIES","SPELLING","VERBAL","VOCATIONAL APTITUDE","YORUBA","ENGLISH","MATHEMATICS"]},"ClassListWithScoreheadsOffered":{"BASIC1 MBADUGHA":["EXAM (100 marks)","EXAM (20 marks)","EXAM (30 marks)","EXAM (50 marks)","TEST (100 marks)","TEST (20 marks)","TEST (30 marks)","TEST (50 marks)"],"BASIC1 OMOTAYO":["EXAM (100 marks)","EXAM (20 marks)","EXAM (30 marks)","EXAM (50 marks)","TEST (100 marks)","TEST (20 marks)","TEST (30 marks)","TEST (50 marks)"],"BASIC1 SOGBESAN":["EXAM (100 marks)","EXAM (20 marks)","EXAM (30 marks)","EXAM (50 marks)","TEST (100 marks)","TEST (20 marks)","TEST (30 marks)","TEST (50 marks)"]},"ClassGroupsOrdered":["BASIC1"],"SessionBoundTableRecords":["scores"]}

Sample of JSON string dumped to the temp file from those PCs with wrong output:

{"‪‪‏‫‌‌‫‬‪‎​‎‭‫‍‎‌​‎‬‎‭‌‮‭​‍‭‮":{"personal_db":[{"id":"1","pixFile":"","regNo":"CSS/1819/1","custom_school_id":"","house":"","std_name":"ADETUNMBI FUNMLADE","dob":"","pob":"","dateOfAdmission":"","classAdmitted":"BASIC1 OMOTAYO","religion":"","homeTown":"","lga":"","state":"","Nationality":"","parentName":"","parentContact":"0","parentEmail":"","siblings":"","occupation":"","positionInFamily":"","health":"","prevSchool":"","prevClassAtPreviousSchool":"","reasonForLeaving":"","currClass":"BASIC1 OMOTAYO","ssclassif":"","sex":"","dropped":"false","graduated":"false","session_admitted":"2018/2019","session_dropped":"","term_dropped":"0","session_graduated":"","date_graduated":"","sort_group":""},{"id":"2","pixFile":"","regNo":"CSS/1819/2","custom_school_id":"","house":"","std_name":"AJADI DEBORAH","dob":"","pob":"","dateOfAdmission":"","classAdmitted":"BASIC1 OMOTAYO","religion":"","homeTown":"","lga":"","state":"","Nationality":"","parentName":"","parentContact":"0","parentEmail":"","siblings":"","occupation":"","positionInFamily":"","health":"","prevSchool":"","prevClassAtPreviousSchool":"","reasonForLeaving":"","currClass":"BASIC1 OMOTAYO","ssclassif":"","sex":"","dropped":"false","graduated":"false","session_admitted":"2018/2019","session_dropped":"","term_dropped":"0","session_graduated":"","date_graduated":"","sort_group":""}],"staff_records":[],"std_class_session_data":[{"id_sessional":"1","regno_sessional":"CSS/1819/1","session":"2018/2019","class":"BASIC1 OMOTAYO","ssclassif_sessional":"","location":"","date_entered":"3/18/2019 7:49:39 AM"},{"id_sessional":"2","regno_sessional":"CSS/1819/2","session":"2018/2019","class":"BASIC1 OMOTAYO","ssclassif_sessional":"","location":"","date_entered":"3/18/2019 7:49:41 AM"}],"score_headers":[{"id":"17","name":"TEST (100 marks)","max_obtainable_score":"100","class_group":"","display_on_result":"yes","display_on_midterm_report":"no","mapped_score_header":"","is_exam":"","is_display_score_header":"","display_as":"TEST","session":"2018/2019","created_at":"2019-03-18 07:51:48"},{"id":"18","name":"EXAM (100 marks)","max_obtainable_score":"100","class_group":"","display_on_result":"yes","display_on_midterm_report":"no","mapped_score_header":"","is_exam":"","is_display_score_header":"","display_as":"EXAM","session":"2018/2019","created_at":"2019-03-18 07:51:48"}],"scores":[]},"​‎‏‏‬‪‎‮‏‭‫‭‍‪‍‏‏‏​‫​‫‍‪​‫‌‮":{"BASIC1 MBADUGHA":["ART","BASIC SCIENCE","COMPOSITION","COMPUTER","ENGLISH","FRENCH","HEALTH EDUCATION","MATHEMATICS","MUSIC","PHONICS","QUANTITATIVE","READING","RELIGION","SOCIAL STUDIES","SPELLING","VERBAL","VOCATIONAL APTITUDE","YORUBA","ENGLISH","MATHEMATICS"],"BASIC1 OMOTAYO":["ART","BASIC SCIENCE","COMPOSITION","COMPUTER","ENGLISH","FRENCH","HEALTH EDUCATION","MATHEMATICS","MUSIC","PHONICS","QUANTITATIVE","READING","RELIGION","SOCIAL STUDIES","SPELLING","VERBAL","VOCATIONAL APTITUDE","YORUBA","ENGLISH","MATHEMATICS"],"BASIC1 SOGBESAN":["ART","BASIC SCIENCE","COMPOSITION","COMPUTER","ENGLISH","FRENCH","HEALTH EDUCATION","MATHEMATICS","MUSIC","PHONICS","QUANTITATIVE","READING","RELIGION","SOCIAL STUDIES","SPELLING","VERBAL","VOCATIONAL APTITUDE","YORUBA","ENGLISH","MATHEMATICS"]},"‫‌‌​‍‏‮‍‌​​‌‪‭‍‬‮‪‍‬‏‍‮":{"BASIC1 MBADUGHA":["EXAM (100 marks)","EXAM (20 marks)","EXAM (30 marks)","EXAM (50 marks)","TEST (100 marks)","TEST (20 marks)","TEST (30 marks)","TEST (50 marks)"],"BASIC1 OMOTAYO":["EXAM (100 marks)","EXAM (20 marks)","EXAM (30 marks)","EXAM (50 marks)","TEST (100 marks)","TEST (20 marks)","TEST (30 marks)","TEST (50 marks)"],"BASIC1 SOGBESAN":["EXAM (100 marks)","EXAM (20 marks)","EXAM (30 marks)","EXAM (50 marks)","TEST (100 marks)","TEST (20 marks)","TEST (30 marks)","TEST (50 marks)"]},"‏‮‮​‫‬‎‏‌‌‮‍‪‏‪‭‎​‍‌‮‌‎‮":["BASIC1"],"‫‮‍‭‪‍‎‏‍‫​‍‪​‍‍‍‪‏‌‮‪‮":["scores"]}

You notice from the difference in output: the JSON string is reversed on those PCs, with strings like session now represented as noisses, marks as skram...etc.

The only obvious differences between those computers and mine is that I am using a 32 bit Windows 7 PC while theirs is 64 bit Windows 10. Even more confusing now is the fact that I got another Windows 10 PC where everything works perfectly exactly like my own Win 7 computer.

EDIT:

Link to my Drive folder containing the good and th bad JSON temp file dumps

Damilola Olowookere
  • 2,253
  • 2
  • 23
  • 33
  • It would appear to me that the file is okay, but the program you are viewing it with does not fully realise it's UTF-8. Try outputting the [byte order mark](https://en.wikipedia.org/wiki/Byte_order_mark) to the file before dumping the string, or try a different encoding (UTF-16?). The viewer apparently interprets some character as [RLM](https://en.wikipedia.org/wiki/Right-to-left_mark) and reverses the text. – GSerg Mar 19 '19 at 06:40
  • @GSerg I have added link to the raw files – Damilola Olowookere Mar 19 '19 at 06:54
  • @DamilolaOlowookere, I observe you jsons provided and only difference is that json `Keys` are converted to `?????` from `bad-format-json` so could you please explain what 's the meaning of **problematic PCs** that gives such `bad-format-json`? – er-sho Mar 19 '19 at 07:01
  • 1
    Yep. Open the bad file in Notepad++ and go Encoding - Convert to ANSI. The strings will all be reversed back, and the offending parts will be replaced with `??`s. – GSerg Mar 19 '19 at 07:01
  • @er-sho They are not missing, they are invisible. – GSerg Mar 19 '19 at 07:03
  • @er-sho by **problematic PCs**, I mean the PCs I as referring to in my question where I said "On some other PCs (my other app users), output is reversed/garbled" – Damilola Olowookere Mar 19 '19 at 07:03
  • @GSerg, yes I updated my answer . I see without converting to ANSI. – er-sho Mar 19 '19 at 07:04
  • @GSerg So what do you suggest caused such question mark chars please???? – Damilola Olowookere Mar 19 '19 at 07:05
  • I think it not a problem of serializer either json.net or any else. It might be a problem of file save code. – er-sho Mar 19 '19 at 07:05
  • @er-sho...and that's why I put the code of the file save – Damilola Olowookere Mar 19 '19 at 07:06
  • @DamilolaOlowookere, did you tried with `Encoding.Default` ? – er-sho Mar 19 '19 at 07:13
  • That is pretty weird actually. The contents of the keys (the part that in the good file contains "TableRecords") is not controlled by you, it is generated automatically by the serializer. In the bad file it contains a nonsensical sequence of ["E2 80 XX" characters](https://www.utf8-chartable.de/unicode-utf8-table.pl?start=8192&number=128) (use a hex viewer), and nothing but those. None of them are visible, but they do mess up rendering of other things. I do not see how a property named `TableRecords` could result in such codepoint sequence, unless the .NET installation is seriously damaged. – GSerg Mar 19 '19 at 07:18
  • @DamilolaOlowookere, I think **GSerg** is right here the **problematic PC** has damaged `.Net Installation.` – er-sho Mar 19 '19 at 07:31
  • Thanks @everyone. I will advice the PC owners to reinstall .NET, and then revert back here for the update – Damilola Olowookere Mar 19 '19 at 08:02
  • @GSerg it's a Windows 10. Cannot reinstall .NET. Any advice? – Damilola Olowookere Mar 19 '19 at 12:39
  • @DamilolaOlowookere https://dotnet.microsoft.com/download/dotnet-framework-runtime/net472? Also, try changing your target FW version. – GSerg Mar 19 '19 at 14:26

0 Answers0