Well the question here is that I'm working on a razor file and I'm wanting to create a json from an array in vb.net
as follows:
For Each ItineraryPnr In ItinerariesNode.ChildNodes
arrayPnrRetrieve(contPnr) = New With {Key .trasactionId = ItineraryPnr.SelectSingleNode("TransactionId").InnerText, .isSucces = False, .provider = ItineraryPnr.SelectSingleNode("Provider").InnerText, .pnr = ItineraryPnr.SelectSingleNode("PNR").InnerText, .errors = Nothing}
contPnr = contPnr + 1
Next
Dim serializerPnrModel As New JavaScriptSerializer()
Dim jsonPnrRQ As String = serializerPnrModel.Serialize(arrayPnrRetrieve)
The above generates something like the following and I assign it to variable jsonPnrRQ
:
[
{
"trasactionId":"c592360b-3d29-4689-9683-8b53b4880099",
"isSucces":false,
"provider":"4O",
"pnr":"DBZD2N",
"errors":null
}
]
Then when wanting to assign it to a variable javascript
in the following way:
@<script>
var metadata = {};
metadata.jsonEx = {};
metadata.jsonEx.pnrRetrieve = @jsonPnrRQ;
metadata.jsonEx.sequenceNumber = "3";
</script>
It leaves me cycled the page and it sends me a syntax error, being that the variable jsonPnrRQ
when debugging it is in a correct format.
The error is as follows:
Uncaught SyntaxError: Unexpected token &
The question would be if someone has happened to him and he has some solution for this?
When printing my object
Js
shows it to me in the following way
metadata.jsonEx = {};
metadata.jsonEx.pnrRetrieve = [{"trasactionId":"c592360b-3d29-4689-9683-8b53b4880099","isSucces":false,"provider":"4O","pnr":"DBZD2N","errors":null}];
metadata.jsonEx.sequenceNumber = "3";
And I think that may be the problem, so, the other question would be, does anyone have any idea why they assign it to me and how can I solve it? being that the variable jsonPnrRQ
has its value well (this is because aldebugearlo comes out with the correct format).