Resolved Preserving Legacy Data

ESoltay

Member
Joined
Feb 1, 2022
Messages
10
Programming Experience
10+
I have been importing a JSON file with VS script for about 6 yrs. Variables have been added during the past 6yrs and I was able to handle the legacy data with the added code 'ContainsKey' on the mapping code. (ex.
C#:
nba_draw_result = record.ContainsKey("nba_draw_result") == true && record["nba_draw_result"] != "" ? record["nba_draw_result"] : null
)

Recently a variable was added ("grouping_uuid") within the 'metadata' array and I'm having trouble trying to utilize the ContainsKey with a list name/ChildrenToken within an array. (ex
C#:
grouping_uuid = record.ContainsKey(record["metadata"]["grouping_uuid"]) == true && record["metadata"]["grouping_uuid"] != "" ? Convert.ToInt32(record["metadata"]["grouping_uuid"]) : null
).

simplified version of the JSON file:
C#:
[
  {
    "nba_draw_result": "",
    "metadata": {
      "grouping_uuid": 193504398
    }
  },
]
I've been struggling for about a week and any help will be greatly appreciated. Thank you.

Best Regards
 
Last edited by a moderator:
Notice line 281 of post #14. It is the same as your call to Deserialize Object<T>().

EF6 does not come into play with all the read operations from your data structure. It may come into play when you assign those read dynamic objects and stuff them into object which you later have EF try to write into a database. Your choice to use dynamic objects makes things very hard pin things down because object types will be determined at runtime.
 
The first ContainsKey comes from the Dictionary library. If you hover over it you get a popup with its description. the second ContainsKey does not have the same popup.

is it possible that the 2 ContainsKey are referenced from different libraries?
 
Last edited:
Yes, that is correct. The type cannot be determined at edit/design time because you chose to make the type of the values Dictionary<TKey, TValue> to be dynamic as I was alluding to in post #16. If you read the popup closely, it tells you that the type will be determined at runtime:
Screenshot_1.png


So when you run the code, you will see that the object ends as a JObject:
Screenshot_2.png


JObject implements IDictionary<TKey, TValue>. And as you know, that interface includes the method ContainsKey().

 
Last edited:
Thank you very much for your time. I have resolved the issue and utilized your code as well. I simply updated the NuGet package and all of your code SUDDENLY worked. Go Figure :rolleyes:

Thank you again, could not have done it without your help!!!!
 
Back
Top Bottom