F
F
Felino2018-05-22 17:23:24
JSON
Felino, 2018-05-22 17:23:24

What's wrong with reactJS JSON?

function Comment(props) {
        return (
            <div >
                {props.General.firstName}
                {props.General.FirstName}
                {props.General.LastName}
            </div>
        );
    }

    var comment = JSON.parse('[{\n' +
        '    general": {\n' +
        '      "firstName": "Liana",\n' +
        '      "lastName": "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": "[email protected]",\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' +
        '      "firstName": "Deontae",\n' +
        '      "lastName": "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": "[email protected]",\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(comment)

    ReactDOM.render(
        <Comment
            General={comment.general}
            Job={comment.job}
            Contact={comment.contact}
            Adress={comment.address}/>,
        document.getElementById('root')
    );

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2018-05-22
@Felino

You have several errors at once:
Probably, it should be something like this , for example.

A
Anton Spirin, 2018-05-22
@rockon404

Learn to read errors in the console. Your JSON is not valid. At least the first general key is missing an opening quote. Why did you even need to define the data as a string on the client and parse it? If you really want to do these meaningless operations, then write better like this:

const json = JSON.stringify([
  {
    general: { /* ... */ },
    /* ... */
  },
  /* ... */
]);

const comments = JSON.parse(json);

it will be more readable, and less likely to make a mistake, and most importantly, you can quickly and easily cut out a meaningless part of the code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question