Felino
@Felino

Angular Json error?

Всем привет!
Подскажите, если не сложно!
[
  {
    "general": {
      "firstName": "Liana",
      "lastName": "Crooks",
      "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/kevinoh/128.jpg"
    },
    "job": {
      "company": "Ledner, Johnson and Predovic",
      "title": "Investor Functionality Coordinator"
    },
    "contact": {
      "email": "Gerry_Hackett77@gmail.com",
      "phone": "(895) 984-0132"
    },
    "address": {
      "street": "1520 Zemlak Cove",
      "city": "New Devon",
      "zipCode": "42586-7898",
      "country": "Guinea-Bissau"
    }
  },
  {
    "general": {
      "firstName": "Deontae",
      "lastName": "Dare",
      "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/andysolomon/128.jpg"
    },
    "job": {
      "company": "D'Amore, Dicki and Borer",
      "title": "International Applications Consultant"
    },
    "contact": {
      "email": "Kellie.Marvin38@yahoo.com",
      "phone": "1-615-843-3426 x600"
    },
    "address": {
      "street": "65901 Glover Terrace",
      "city": "Alden ton",
      "zipCode": "57744-4248",
      "country": "Kenya"
    }
  }
]


Запускаю "server": "json-server --watch test.json --port 3000"
Ошибка: Data must be an object. Found object.See https://github.com/typicode/json-server for example.
Подскажите в чем может быть трабл? Не магу понять в чем кривость JSON. Понимаю что не находит объект. Но когда я делаю объект лезут другие ошибки!
вот пример!
{
    "general": [{
      "firstName": "Liana",
      "lastName": "Crooks",
      "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/kevinoh/128.jpg"
    }],
    "job": [{
      "company": "Ledner, Johnson and Predovic",
      "title": "Investor Functionality Coordinator"
    }],
    "contact": [{
      "email": "Gerry_Hackett77@gmail.com",
      "phone": "(895) 984-0132"
    }],
    "address": [{
      "street": "1520 Zemlak Cove",
      "city": "New Devon",
      "zipCode": "42586-7898",
      "country": "Guinea-Bissau"
    }]
  },
  {
    "general": [{
      "firstName": "Deontae",
      "lastName": "Dare",
      "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/andysolomon/128.jpg"
    }],
    "job": [{
      "company": "D'Amore, Dicki and Borer",
      "title": "International Applications Consultant"
    }],
    "contact": [{
      "email": "Kellie.Marvin38@yahoo.com",
      "phone": "1-615-843-3426 x600"
    }],
    "address": [{
      "street": "65901 Glover Terrace",
      "city": "Alden ton",
      "zipCode": "57744-4248",
      "country": "Kenya"
    }]
  }

SyntaxError: Malformed JSON in file: clients.json
Unexpected token ',' at 21:4
},
^
  • Вопрос задан
  • 88 просмотров
Решения вопроса 1
EreminD
@EreminD
Кое-что умею
  1. Открываете https://jsoneditoronline.org/
  2. Вставляете совой второй json в него
  3. Видите ошибку - Parse error on line 21:
  4. Нельзя передать два объекта через запятую: или массив, или оберните это все в объект


Возможные решения:
Массив
[
  {
    "general": [
      {
        "firstName": "Liana",
        "lastName": "Crooks",
        "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/kevinoh/128.jpg"
      }
    ],
    "job": [
      {
        "company": "Ledner, Johnson and Predovic",
        "title": "Investor Functionality Coordinator"
      }
    ],
    "contact": [
      {
        "email": "Gerry_Hackett77@gmail.com",
        "phone": "(895) 984-0132"
      }
    ],
    "address": [
      {
        "street": "1520 Zemlak Cove",
        "city": "New Devon",
        "zipCode": "42586-7898",
        "country": "Guinea-Bissau"
      }
    ]
  },
  {
    "general": [
      {
        "firstName": "Deontae",
        "lastName": "Dare",
        "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/andysolomon/128.jpg"
      }
    ],
    "job": [
      {
        "company": "D'Amore, Dicki and Borer",
        "title": "International Applications Consultant"
      }
    ],
    "contact": [
      {
        "email": "Kellie.Marvin38@yahoo.com",
        "phone": "1-615-843-3426 x600"
      }
    ],
    "address": [
      {
        "street": "65901 Glover Terrace",
        "city": "Alden ton",
        "zipCode": "57744-4248",
        "country": "Kenya"
      }
    ]
  }
]
Объект
{
  "a": {
    "general": [
      {
        "firstName": "Liana",
        "lastName": "Crooks",
        "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/kevinoh/128.jpg"
      }
    ],
    "job": [
      {
        "company": "Ledner, Johnson and Predovic",
        "title": "Investor Functionality Coordinator"
      }
    ],
    "contact": [
      {
        "email": "Gerry_Hackett77@gmail.com",
        "phone": "(895) 984-0132"
      }
    ],
    "address": [
      {
        "street": "1520 Zemlak Cove",
        "city": "New Devon",
        "zipCode": "42586-7898",
        "country": "Guinea-Bissau"
      }
    ]
  },
  "b": {
    "general": [
      {
        "firstName": "Deontae",
        "lastName": "Dare",
        "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/andysolomon/128.jpg"
      }
    ],
    "job": [
      {
        "company": "D'Amore, Dicki and Borer",
        "title": "International Applications Consultant"
      }
    ],
    "contact": [
      {
        "email": "Kellie.Marvin38@yahoo.com",
        "phone": "1-615-843-3426 x600"
      }
    ],
    "address": [
      {
        "street": "65901 Glover Terrace",
        "city": "Alden ton",
        "zipCode": "57744-4248",
        "country": "Kenya"
      }
    ]
  }
}
Массив в объекте - самый подходящий
{
  "data": [
    {
      "general": {
        "firstName": "Liana",
        "lastName": "Crooks",
        "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/kevinoh/128.jpg"
      },
      "job": {
        "company": "Ledner, Johnson and Predovic",
        "title": "Investor Functionality Coordinator"
      },
      "contact": {
        "email": "Gerry_Hackett77@gmail.com",
        "phone": "(895) 984-0132"
      },
      "address": {
        "street": "1520 Zemlak Cove",
        "city": "New Devon",
        "zipCode": "42586-7898",
        "country": "Guinea-Bissau"
      }
    },
    {
      "general": {
        "firstName": "Deontae",
        "lastName": "Dare",
        "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/andysolomon/128.jpg"
      },
      "job": {
        "company": "D'Amore, Dicki and Borer",
        "title": "International Applications Consultant"
      },
      "contact": {
        "email": "Kellie.Marvin38@yahoo.com",
        "phone": "1-615-843-3426 x600"
      },
      "address": {
        "street": "65901 Glover Terrace",
        "city": "Alden ton",
        "zipCode": "57744-4248",
        "country": "Kenya"
      }
    }
  ]
}
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы