Hi I’m a complete newbie to json. I’m trying to parse a json file into a web page just like explained in this thread………
However my json file is a large list of contacts that are not in an array like ‘people’ in the above example. instead the first 6 lines of my json file are like the following.
{ "first_name": "Tom", "last_name": "Moore", "phone": "123456", "email": "tom@abc.ie" }
{ "first_name": "Fred", "last_name": "Power", "phone": "197412", "email": "fred@abc.ie" }
{ "first_name": "Ann", "last_name": "Doyle", "phone": "836547", "email": "ann@abc.ie" }
{ "first_name": "Phil", "last_name": "Jones", "phone": "927481", "email": "phil@abc.ie" }
{ "first_name": "Jane", "last_name": "Ross", "phone": "993377", "email": "jane@abc.ie" }
{ "first_name": "Tom", "last_name": "Moore", "phone": "123456", "email": "tom@abc.ie" }
How can I loop through them to display like in the above thread? Many thanks in advance.
Your json is invalid. It needs square brackets around the outside, and commas between items. It should be:
$.getJSONhandles the json parsing for you – just do: