im trying to convert this json string to object, but i can't, the console this erro:
Uncaught SyntaxError: Unexpected end of JSON input
at JSON.parse (<anonymous>) at Vue$3.buildResults (rolList.js:422) at Vue$3.boundFn [as buildResults] (vue.js:141) at Vue$3.mounted (rolList.js:418) at callHook (vue.js:2768) at Vue$3.Vue._mount (vue.js:2630) at Vue$3.$mount (vue.js:6186) at Vue$3.$mount (vue.js:8557) at Vue$3.Vue._init (vue.js:3389) at new Vue$3 (vue.js:3437)
The json string is this:
{"modulos":{"1":{"name":" Usuarios","paginas":{"1":{"name":" Listado Usuarios","facultades":{"1":{"name":" ver"}}}}}}}
The java script code is this:
resultsLi = new Vue({
el: '#result-list',
data: {
resultls: "",
json: []
},
mounted: function () {
this.buildResults();
},
methods: {
buildResults: function(event) {
this.json = JSON.parse(this.resultls);
console.log(this.resultls);
}
},
watch: {
resultls: function(val, oldVal){
this.buildResults();
}
},
delimiters: ['${', '}']
});
this
what you think it's supposed to be inside thebuildResults
definition? Should you havethis.data.resultls
instead? Ifthis
is supposed to be yourresultsLi
, thenthis.resultls
andthis.json
are bothundefined
as they are a child of thedata
property. – Cᴏʀʏ Mar 9 at 16:18code
resultsLi.resultls = JSON.stringify(tempList);code
because the vue whatcher not detecting changes in the object when i add elements only if i convert the json in to json string – Brayan Caldera Mar 9 at 16:21console.log(typeof this.results)
on the line before you callJSON.parse()
if the result is 'object', then you don't need to callJSON.parse()
– jessegavin Mar 9 at 16:27data
object, sothis.resultls
would work. My remaining question then would be whether its value is what you think it is. – Cᴏʀʏ Mar 9 at 16:27