javascript - How to parse a JSON response in jQuery? -
I am making a small web app for my girlfriend and I will be allowed to keep track of the movies that we want To make it easier to add a movie to the list to watch together, I'm trying to use TheMovieDatabase.org's API (only supports Jasonson) so that we can find a movie titled Can allow the database to load some results, and We then if no results had to choose just add a movie database or listing of our own.
I am using jQuery to handle everything, and I have never used JSON before, I wrote a little bit of code to get JSON based on my search query , And now with the result and lt; Ul & gt;
I'm trying to populate it. I have it.
var TMDbAPI = "https://api.themoviedb.org/3/search/movie"; Var moviequery = $ ("#search"). Val (); Var api_key = "baab01130a70a05989eff64f0e684599"; $ Ul = $ ('ul'); $ .getJSON (TMDbAPI, {query: moviequery, api_key: api_key}, function (data) {$ .each (data, function (k, v) {$ ul.append ("& lt; li & gt;" + k + ":" + V + "& lt; / li & gt;");});});
JSON file is structured as
{"page": 1, "result": [{"adult": false, "Backdrop_path": "/ HNFMYYWZKK4GVCBiz1KRRMJPGI", "AD": 550, "Original-Title": "Fight Club", "Release_date": "1999-10-14", "Poster_path": "/ 2 LEPPI 4HN BP4Y46JX 0AA3WTE.JPG "," Popularity ": 13.30 9 5569670529," Title ":" Fight Club "," VoteAverage ": 7.7," Votekount ": 2927} .. ... "total_page": 1, "total_first": 10}
but All I am getting is
Page: 1 Result: [object object], ... total_page: 1 total_proportion 10
I have searched the solution For quite a large scale on the Internet, but with little knowledge of JSON I was not able to learn a lot from different examples and answers about which I got scattered. What does it do?
It looks like what you want to do, in some attributes list of each movie. This means that you want a loop in this list in data.results
:
// "result" array $ .Every result from IE (data ( $ Li);} $ li.text (movie.title); $ ul.append ($ li);});
This movie will make a list of titles. If you want to show more detailed information, you can use the other properties of each
function within movie
.
I have since
li to avoid these problems, if any movie title $ ('
since < If using any code> $ li.text & lt; The symbols have to be included, which can then be interpreted as an HTML tag and make some strange rendering, although it is unlikely that in a movie title it will be a symbol, this simple extra step will give your code more Makes strong and so is a good habit of keeping it.
Comments
Post a Comment