Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Problem with the passage of a json string in javascript

$
0
0

Hello everyone, I'm developing in asp.net mvc core and use c #, I need to move to javascript a json string representing an array of objects.

After processing "ViewData["Data"] = Newtonsoft.Json.JsonConvert.SerializeObject(ObjectsArray);" get :

[{"id":"0","parent":"#","text":"server","level":0,"folderName":"server","folderPath":"Z:\\csi\\server","fileItems":[
{"fileName":"serverfile1","filePath":"Z:\\csi\\server\\serverfile1.txt","fileExtension":".txt"},
{"fileName":"serverfile2","filePath":"Z:\\csi\\server\\serverfile2.txt","fileExtension":".txt"},
{"fileName":"serverfile3","filePath":"Z:\\csi\\server\\serverfile3.txt","fileExtension":".txt"}]}]

In javascript I process the following statement "var data = JSON.parse(@Convert.ToString(ViewData["Data"]));" giving me this error:

Errore critico JavaScript alla riga 87, colonna 36 in http://localhost:9191/\n\nSCRIPT1028: Previsto identificatore, stringa o numero

at this row:

var data = JSON.parse([{"id":"0","parent":"#","text":"server","level":0,"folderName":"server","folderPath":"Z:\\csi\\server","fileItems":[
{"fileName":"serverfile1","filePath":"Z:\\csi\\server\\serverfile1.txt","fileExtension":".txt"},
{"fileName":"serverfile2","filePath":"Z:\\csi\\server\\serverfile2.txt","fileExtension":".txt"},
{"fileName":"serverfile3","filePath":"Z:\\csi\\server\\serverfile3.txt","fileExtension":".txt"}]}];

The statement I took during debugging.


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>