javascript - How to properly decode a JSON string encoded using Html.Raw(Json.Encode(Model))? -


i encoding model data html element this:

@html.raw(json.encode(model)); 

the json string returned looks this:

{"testlist":[{"frequencytype":"1x","gcds":"585.6","identifier":"6144","seqno":9306,"seqnospecified":true,"tseqno":8314,"tseqnospecified":true,"testdescr":"hbsag"},{"frequencytype":"1x","gcds":"585.6","identifier":"6124","seqno":9295,"seqnospecified":true,"tseqno":8315,"tseqnospecified":true,"testdescr":"hcv ab"},{"frequencytype":"1x","gcds":"585.3","identifier":"6","seqno":9729,"seqnospecified":true,"tseqno":8309,"tseqnospecified":true,"testdescr":"hd monthly ls"}],"frequency":[{"key":"annual","value":"annually"},{"key":"bimonth","value":"bi-monthly"},{"key":"biweek","value":"bi-weekly"},{"key":"mon","value":"monthly"},{"key":"1x","value":"one time"},{"key":"qtr","value":"quarterly"},{"key":"sman","value":"semi-annual"},{"key":"week","value":"weekly"}]}; 

when try parse using json.parse, error:

arraytestlist = []; var jsontestlist = $('#testlist').text(); jsontestlist = json.stringify(jsontestlist); arraytestlist = json.parse(jsontestlist); alert(arraytestlist.testlist[0]); // <===== line failing  unable value of property '0': object null or undefined 

how convert jsontestlist string javascript array can access elements of arraytestlist properly?

edit:

sorry, forgot mention edit. above javascript code inside partial view 2. code json encoding model in partial view 1. p v 2, cannot access model object of p v 1, dumping contents div tag, can access list testlist element.

try removing line:

jsontestlist = json.stringify(jsontestlist); 

jsontestlist json string


Comments