admin管理员组文章数量:1312774
I'm trying to dynamically build a vuetify ponent in a nuxt project (Using different text values with vuetify ponent) by importing and iterating through json in a module ().
My json in /static/info.json is:
{
"id": 1,
"name": "Johnson, Smith, and Jones Co.",
"amount": 345.33,
"Remark": "Pays on time"
}
In my vue ponent I have:
import * as data from '../static/info.json';
const word = data.name;
console.log(word); // output 'testing'
console.log(data); // output 'testing'
var jsonData = JSON.parse(data);
// console.log(jsonData); // output 'testing'
The line:
var jsonData = JSON.parse(data);
causes:
Cannot convert object to primitive value
How can I iterate through the imported json?
I'm trying to dynamically build a vuetify ponent in a nuxt project (Using different text values with vuetify ponent) by importing and iterating through json in a module (https://hackernoon./import-json-into-typescript-8d465beded79).
My json in /static/info.json is:
{
"id": 1,
"name": "Johnson, Smith, and Jones Co.",
"amount": 345.33,
"Remark": "Pays on time"
}
In my vue ponent I have:
import * as data from '../static/info.json';
const word = data.name;
console.log(word); // output 'testing'
console.log(data); // output 'testing'
var jsonData = JSON.parse(data);
// console.log(jsonData); // output 'testing'
The line:
var jsonData = JSON.parse(data);
causes:
Cannot convert object to primitive value
How can I iterate through the imported json?
Share Improve this question asked Jan 19, 2019 at 16:42 user1592380user1592380 36.4k105 gold badges312 silver badges551 bronze badges 1- Are you exporting something from json file ? – Abhishek Commented Jan 19, 2019 at 17:16
1 Answer
Reset to default 7I would guess data is already an object and doesn't need to be parsed again. The import has turned it into an object. You've already used it with data.name
本文标签: javascriptCannot convert object to primitive value with imported jsonStack Overflow
版权声明:本文标题:javascript - Cannot convert object to primitive value with imported json - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741887685a2403119.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论