user1086010
user1086010

Reputation: 697

Node.js read json from google api

i try to get google suggestion from this url http://suggestqueries.google.com/complete/search?q=bob&client=firefox

when i run the url i get this result : ["bob",["bobby shmurda","bob marley","bobbi kristina","bobbi brown","bobbi kristina brown","bob dylan","bob evans","bobby hurley","bob\u0027s burgers","bob seger"]]

in node.js i used request , heres my code :

var request = require('request');
var url = 'http://suggestqueries.google.com/complete/search?q=bob&client=firefox';
 request(url,function(error, response, result){
    if(!error){
    console.log(result);

    }

 });

until now everythings work fine as you can see my output is an array with two values, in above code when i try to get result[1]instead of show array its just show a ". i dont know why this happen.

Upvotes: 0

Views: 242

Answers (2)

Tuan Anh Tran
Tuan Anh Tran

Reputation: 7237

try to parse it first

var json_data = JSON.parse(result);  

Upvotes: 0

David Haim
David Haim

Reputation: 26476

probably because you get a String and not a JSON. try JSON.parse

result = JSON.parse(result)

Upvotes: 1

Related Questions