I have JSON data and I am trying to parse it using JSON.parse()
. I keep getting the error: unexpected token o
. Could someone help?
I feel I should mention that I'm going to be using the parsed JSON data to populate a Dojo store which will then be used to populate a Dijit Tree. Would anyone recommend any other method to form a tree UI?
This is my code.
$(document).ready(function(){
require([
"dojo/ready", "dojo/_base/window", "dojo/json","dojo/dom","dojo/store/Memory", "dojo/store/Observable",
"dijit/tree/ObjectStoreModel", "dijit/Tree", "dojo/domReady!", "dojo/mouse","dojo/text!./data/all.json"],
function(ready, win, JSON, dom, Memory, Observable, ObjectStoreModel, Tree, mouse, data){
var testStore = new Memory({
data : JSON.parse($("#getData").click(
function(){
var inputString = "pspTreegetData{}";
var state = Function that executes Tcl script and returns the JSON data
return state;
})),
This is my Tcl script which gives the raw JSON data when I check its output,
proc pspTreegetData {} {
set fo [open "C:/Path/To/File/sampleTest.json" r]
set text [read $fo]
close $fo
puts $text
return $text
}
My Json file is as follows,
[
{
"name" : "root",
"id" : "rootNode",
"description" : "This is the root node"
},
{
"name" : "level1_node1",
"id" : "l1n1",
"description" : "This is the first node of level 1",
"parent" : "rootNode"
},
{
"name" : "level2_node1",
"id" : "l2n1",
"description" : "This is the first node of level 2",
"parent" : "l1n1"
},
{
"name" : "level2_node2",
"id" : "l2n2",
"description" : "This is the second node of level 2",
"parent" : "l1n1"
},
{
"name" : "level3_node1",
"id" : "l3n1",
"description" : "This is the first node of level 3",
"parent" : "l2n2"
},
{
"name" : "level3_node2",
"id" : "l3n2",
"description" : "This is the second node of level 3",
"parent" : "l2n2"
},
{
"name" : "level1_node2",
"id" : "l1n2",
"description" : "This is the second node of level 1",
"parent" : "rootNode"
},
{
"name" : "level1_node3",
"id" : "l1n3",
"description" : "This is the third node of level 1",
"parent" : "rootNode"
},
{
"name" : "level2_node3",
"id" : "l2n3",
"description" : "This is the third node of level 2",
"parent" : "l1n3"
},
{
"name" : "level2_node4",
"id" : "l2n4",
"description" : "This is the fourth node of level 2",
"parent" : "l1n3"
},
{
"name" : "level1_node4",
"id" : "l1n4",
"description" : "This is the fourth node of level 1",
"parent" : "rootNode"
}
]