Felino
@Felino

Перебрать JSON reactjs?

json
[{
    "general": {
      "Name": "Liana",
      "Name1": "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": {
      "Name": "Deontae",
      "Name1": "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"
    }
  }]

код
var myObject = JSON.parse('[{\n' +
        '    "general": {\n' +
        '      "Name": "Liana",\n' +
        '      "Name1": "Crooks",\n' +
        '      "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/kevinoh/128.jpg"\n' +
        '    },\n' +
        '    "job": {\n' +
        '      "company": "Ledner, Johnson and Predovic",\n' +
        '      "title": "Investor Functionality Coordinator"\n' +
        '    },\n' +
        '    "contact": {\n' +
        '      "email": "Gerry_Hackett77@gmail.com",\n' +
        '      "phone": "(895) 984-0132"\n' +
        '    },\n' +
        '    "address": {\n' +
        '      "street": "1520 Zemlak Cove",\n' +
        '      "city": "New Devon",\n' +
        '      "zipCode": "42586-7898",\n' +
        '      "country": "Guinea-Bissau"\n' +
        '    }\n' +
        '  },\n' +
        '  {\n' +
        '    "general": {\n' +
        '      "Name": "Deontae",\n' +
        '      "Name1": "Dare",\n' +
        '      "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/andysolomon/128.jpg"\n' +
        '    },\n' +
        '    "job": {\n' +
        '      "company": "D\'Amore, Dicki and Borer",\n' +
        '      "title": "International Applications Consultant"\n' +
        '    },\n' +
        '    "contact": {\n' +
        '      "email": "Kellie.Marvin38@yahoo.com",\n' +
        '      "phone": "1-615-843-3426 x600"\n' +
        '    },\n' +
        '    "address": {\n' +
        '      "street": "65901 Glover Terrace",\n' +
        '      "city": "Alden ton",\n' +
        '      "zipCode": "57744-4248",\n' +
        '      "country": "Kenya"\n' +
        '    }\n' +
        '  }]')
    console.log(myObject)

    class People extends React.Component {
        render() {
            return <div>
            <h1 >{this.Name}</h1>
                <h1>{this.Name1}</h1>
                <h1 >{this.company}</h1>
                <h1>{this.street}</h1>
            </div>;
        }
    }
    ReactDOM.render(
        <div>
        <People  />
        </div>,
        document.getElementById('root')
    );



Подскажите как правильно вывести переменный в класс People.
То-есть должно быть два

Name
Name1
company
street


Пытаюся через Array.map Но чет не получается!
  • Вопрос задан
  • 154 просмотра
Пригласить эксперта
Ваш ответ на вопрос

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

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