javascript - How to process an object literal? -


I'm new to JavaScript and am trying to remove some of the text stored in an object.

The object is defined as an object and is passed in the function that calls the function. This structure of script (and object) is:

  foo ({"query": {"count": "2", "created": "2009-07-25T08: 17: 54Z "," Lang ":" n-US ",}," result ": {" results ": [{" abstract ":"  pizza  hut®. Or order online "Domino's Lieutenant; l & gt; Pizza & lt; / b & gt; Official Site of Delivery Chain", "Fast & amp. Az.", "Headline": "& lt; B & gt; Pizza & lt; / b & gt; A variety of thin layer, deep dish and hand side and a variety of Lt; B & gt; Pizza & lt; / b & gt; Site & lt; b & gt; ... & lt; / b & gt; "," title ":" Domino & lt; b & gt; Pizza & lt; / b & gt;  

The object is sent in a callback function called "foo":

  function foo (o) {Var out = document.getElementById ('container'); Out.innerHTML = o.query.count;}  My problem:  I know that the query count variable using the callback function above How to print, but I do not know how to print it The title of the first results in the program array.  

How can I change the callback function to display the first result title? Also, there is a foreach statement, where can I print all the titles from all the results?

Thank you!

Update: JSBIN is for this code:

does the following:

  o.results.result [0] Title  

The first result to get the title? And to iterate on all results:

 for  (var i = 0; i & lt; o.results.result.length; i ++) {var results = o. result. Arbitration [i]; Warning (result.title); }  

EDIT: Are you sure you copy it correctly? What I find in Rhino is:

  js> o "{" query ": {" count ":" 2 "," created ":" 2009-07-25T08: 17: 54Z "," Lang ":" N-US ",}," Result ": {" Result ": [{" Abstract ":" and lieutenant; B & gt; Pizza & lt; / B & gt; HTR Order Online Delivery or Carry Out Fast and Easy "," Title ":" & lt; B & gt; Pizza & lt; Dummies & lt; B & gt; Pizza & lt; / B & gt; Official site of the delivery series, which is thin layer, deep dish and hand is thrown and lieutenant; Pita and lieutenant; & Lt; B & gt; A variety of side items and drinks. Site & lt; B & gt; ... & lt; / B & gt; "," Title ":" Domino's < B & gt; Pizza & lt; / B & gt; "}]}} JS & gt; O.results.result [0] .title  Pizza & lt; / b & gt; Hut  
< / Html>

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -