2

I have no clue whatsoever on how to resolve this. All I can figure out as a way of starting to resolve this is that my dev machine where things work perfectly is a 32 bit and the other tested computers are 64 bit (incidentally there are no other 32 bit machines around me to test with). Regardless, this is a strange scenario.

Now to the issue:

I am using Newtonsoft JSON library in my c# application. I have the following c# class to serialize:

class sync_object
    {

        //newtonJson give bad keys to these object names on 64bit systems

        public Dictionary<string, List<Dictionary<string, string>>> table_records { get; set; }
        public Dictionary<string, List<string>> class_list_with_subjects_offered { get; set; }
        public Dictionary<string, List<string>> class_list_with_scoreheads_offered { get; set; }
        public List<string> class_groups_ordered { get; set; }
    }

After creating an instance of sync_object and filling it with data, I did JsonConvert.SerializeObject(instance_of_sync_object) and send to my server. Then when I log the JSON received at server side (Laravel PHP), I get a perfect JSON dumped in PHP like below:

array ( 'table_records' => array ( 'personal_db' => array (...) ) , 'class_groups' => array(...) )

However, on 2 other computers (my app users), I get the same JSON structure like above, but the only difference is that all first-level JSON keys (like 'table_groups' and 'class_groups_ordered' in the above) gets replaced with the following strange characters (you may want to use your cursor to select it to observe that it contains a lot of non-printable chars):

'‮‫‫‮‮‌​‎​‭‎‏‮‎​‎‪‭‪​‍‮‬‌‏‬‮' => 

As I mentioned earlier, the only obvious difference between those computers and mine is that mine is a 32 bit PC while theirs is 64 bit.

Also, as a way of providing more information, since the JSON dump was done in my Laravel backend with Monolog, I get a peek at the DOM inspector in Chrome, as annotated below:

My normal JSON: enter image description here

The weird JSON from the other guys: enter image description here

The same Newtonsoft Json library is running on all these machines.

Damilola Olowookere
  • 2,253
  • 2
  • 23
  • 33
  • 1
    You should paste text instead of screen captures. – aybe Mar 03 '19 at 22:04
  • @Aybe please read question again more carefully so you'll understand that the corresponding text to the picture was already provided (the picture was to provide more insight to the already provided text) – Damilola Olowookere Mar 03 '19 at 22:08
  • No, you didn't paste the code you are highlighting on your second screenshot. – aybe Mar 03 '19 at 22:14
  • @Aybe It is not an highlight - it is simply what the Chrome inspector displays. When I try to copy it and paste it here, it simply changes to those characters that looks like backwards facing arrow. You can try and select those series of character in that arrow in order to get a feel of what is going on there! – Damilola Olowookere Mar 03 '19 at 22:26
  • Take a look at https://www.w3schools.com/charsets/ref_utf_punctuation.asp and see your codes, this should give you a clue about what's going on under the hood; some invariant culture or normalization should be involved I guess ? i.e. it's all non visible chars, something's wrong at this user's PC when generating the JSON. – aybe Mar 03 '19 at 22:40
  • What I mean by that is you should find out whether your library leverages culture-specific transformations or uses an invariant culture at some point and act accordingly. There are many parts in .NET where you should be aware about culture-involved transformations (`CultureInfo`). – aybe Mar 03 '19 at 22:50
  • @Aybe it will be more helpful if you provide more useful insight. Where in the code snippets above does such culture-specific transformations? It is a simple serialization of object. Where exactly do you advise the consideration of invariant culture in this context? – Damilola Olowookere Mar 03 '19 at 23:03

1 Answers1

0

Instinctively, I changed all my snake_case object property names to PascalCase and the nightmare was over!

(Note: I do not find anything on Newtonsoft JSON documentation that suggests that the case of property names matter in data serialization)

Damilola Olowookere
  • 2,253
  • 2
  • 23
  • 33
  • This just does solve the problem temporarily. The problem now resurfaced. Now even when I swap Newtonsoft for Microsoft's Web.Script.Serialization. [Check the new posted SO question for more details](https://stackoverflow.com/questions/55222091/object-serialization-returns-json-with-garbled-keys-on-windows-10) – Damilola Olowookere Mar 18 '19 at 13:05
  • This means that you have a different problem, not related to JSON. JSON.NET is used by *all* Web API and ASP.NET Core projects. If there was *any* problem, thousands of developers would have noticed – Panagiotis Kanavos Mar 18 '19 at 15:49
  • @PanagiotisKanavos Yeah, you're correct. That is why I re-posted the issue to another question, with a lot more information. – Damilola Olowookere Mar 18 '19 at 16:12
  • Edit: link to the other new posted SO: https://stackoverflow.com/questions/55224030/differences-between-computers-in-json-returned-for-serialized-c-sharp-objects – Damilola Olowookere Mar 18 '19 at 16:13
  • https://superuser.com/questions/1201498/how-to-reinstall-net-framework-4-4-6-on-windows-10, does this help? – xdtTransform Mar 19 '19 at 13:31