I am working on a JSON WPF program-C#... I have 2 objects that I am concatenating. All I need to know is how to format the first block of code to where the data types match. Here is what I have:
I need to take this:
A.)
{
“Name” : “Walder” ,
“Alias” : “Hodor” ,
“Alliance” : “House Stark”
}
and this:
B.)
{
“Name” : “Margaery Tyrell” ,
“Alias” : [ “The Little Queen”, “The Little Rose”, “Maid Margaery”
]
“Alliance” : “House Tyrell”
}
and combine them like this: the exact instructions say take A and B and out them together
{
“Name” : “Walder” ,
“Alias” : “Hodor” ,
“Alliance” : “House Stark”
}
, //comma to connect them
{
“Name” : “Margaery Tyrell” ,
“Alias” : [ “The Little Queen”, “The Little Rose”, “Maid Margaery”
]
“Alliance” : “House Tyrell”
}
However, B.) - the one right above has an array, so I need to make A.) have an array as well. Or do I make the bottom object not have an array? The data types have to match, so how do I accomplish that?
Solution:
If we want to combine two JSON objects then the datatypes must match.
In the first object Alias is of type string and in the second object, Alias contains Array of strings. We want Alias contain the strings of both first and second.
In order to combine the string we have to make first Alias as an array as well.
{
“Name” : “Walder” ,
“Alias” : [“Hodor”] ,
“Alliance” : “House Stark”
},
{
“Name” : “Margaery Tyrell” ,
“Alias” : [ “The Little Queen”, “The Little Rose”, “Maid Margaery”
]
“Alliance” : “House Tyrell”
}
Get Answers For Free
Most questions answered within 1 hours.