I have an vb.net like the next:
Public Shared Function GetCountries()
Dim lCheckOutManager As CheckOutManager = CType(HttpContext.Current.Session("CHECKOUT_MANAGER"), CheckOutManager)
Dim dataResult = lCheckOutManager.getCountries()
Return JsonConvert.SerializeObject(dataResult, Formatting.Indented)
End Function
Which returns a Json object to javascript like the next:
[
{
"ID":12,
"NAME":"Canada",
"INCOTERM":3
},
{
"ID":60,
"NAME":"United States",
"INCOTERM":3
}
]
And as I'm needing to join two json in the response and be able to access them separately, I did a little modification to my method like this:
Public Shared Function GetCountries()
Dim lCheckOutManager As CheckOutManager = CType(HttpContext.Current.Session("CHECKOUT_MANAGER"), CheckOutManager)
Dim dataResult = lCheckOutManager.getCountries()
Dim strDataResult As String = "{Countries:" & JsonConvert.SerializeObject(dataResult, Formatting.Indented) & "}"
Return JsonConvert.SerializeObject(strDataResult, Formatting.Indented)
End Function
So I can identify the first json by the node "Countries" (and then I will concatenate the second JSON), so I get a json like the next:
{
"Countries":[
{
"ID":12,
"NAME":"Canada",
"INCOTERM":3
},
{
"ID":60,
"NAME":"United States",
"INCOTERM":3
}
]
}
But all my attempts to retrieve the "Countries" node are
being unsuccessful. Iv'e tried:
JSON.parse(results[0].d).Countries, JSON.parse(results[0].d)["Countries"], JSON.parse(results[0].d)[0], Object.keys(JSON.parse(results[0].d))[0] but none of them works, as they end in undefined or empty strings.
Any help?