Creating an Array of strings from a stringified JSON
So I have this kind of JSON structure:
and I want to use Newtonsoft.Json to
DeserializeObject<string[]>(sourceJson)
but when I do this, I get "Unexpected character '{' at path: sourceJson line 3 position 5"
Does anyone know how to convert this json into a string[]
or IEnumerable<string>
?
Perhaps I have to use JArray
instead?? I don't know5 Replies
I think you should consider creating objects out of the json source and target arrays instead of just getting string arrays out of them
What are you expecting in the resulting array?
So
sourceJson
should become (eventually) a Dictionary<string, JToken> (or equivalent of JToken where the type is undetermined beforehand)
and so must targetJson
and then I want to do a bunch of comparisons to keys and values before merging or joining the two and returning a result based on that.
I guess eventually this is what I attempt to do:
Dictionary<string, JValue> insertRecords = sourceRecords.Keys.Where(item => !targetRecords.ContainsKey(item)).ToDictionary(item => item, item => sourceRecords[item]);
Create an object with two properties, sourceJson, TargetJson that are arrays of that dictionary
Serialize to that
basically the result should become like this:
the update is because the same value exists in
sourceJson
but has different values