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