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
Add a ment  | 

1 Answer 1

Reset to default 7

I 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