-1

How can I parse "h" value from the following jSON using javascript?

JSON Content:

info = { "title" : "Laura Branigan - Self Control", "image" : "http://i.ytimg.com/vi/p8-pP4VboBk/default.jpg", "length" : "5", "status" : "serving", "progress_speed" : "", "progress" : "", "ads" : "", "pf" : "http://ping.aclst.com/ping.php/2452159/p8-pP4VboBk?h=761944", "h" : "83135b0b3cf927b5e6caf1cf991b66b3" };
1
  • I'm sorry but it looks like you should read some tutorials on AJAX, and possibly try and write a few hello worlds before you tackle this. Commented Jun 16, 2013 at 0:09

4 Answers 4

1

You can try this. I think it is simpler

info.h
Sign up to request clarification or add additional context in comments.

2 Comments

yes is working but how can i get this value from the external url?
I can´t access this url by ajax. I'm receiving this error from console: "XMLHttpRequest cannot load youtube-mp3.org/a/itemInfo/?video_id=p8-pP4VboBk" Can´t you access this parameter directly from youtube site? What does it do?
0

Oh! Now I understand your question. You don't know how to get the response from a url into a javascript variable. You need a small ajax script for this:

var youTubeUrl = "http://www.youtube-mp3.org/a/itemInfo/?video_id=p8-pP4VboBk";

var request = makeHttpObject();
request.open("GET", youTubeUrl, true);
request.send(null);
request.onreadystatechange = function() {
  if (request.readyState == 4){
    eval(request.responseText);//this should create the info variable.
    alert(info.h); //<<<---this should be it!
    //TODO: add your code to handle the info.h here.
    }
};

function makeHttpObject() {
  try {return new XMLHttpRequest();}
  catch (error) {}
  try {return new ActiveXObject("Msxml2.XMLHTTP");}
  catch (error) {}
  try {return new ActiveXObject("Microsoft.XMLHTTP");}
  catch (error) {}

  throw new Error("Could not create HTTP request object.");
}

Code mostly copied from: https://stackoverflow.com/a/6375580/1311434

Note that I haven't tested this code, but I hope it get's you in the right direction. Be sure that you can trust the code you retrieve from the original URL as it's a bit dangerous to eval() code you retrieve from another site.

6 Comments

Browser (Chrome) give the Access-Control-Allow-Origin error. How can i solve this?
start chrome with "[path-to-chrome]\chrome.exe" --disable-web-security
i tried, but problem is same
Strange, it works for me... This is my path: "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-web-security
This is my test file: gist.github.com/anonymous/5789615
|
0

The string you have above is a complete JavaScript object, You can think of this as a hash table or an associative key array where "key":"value" if you want to index into this array or object you simply use it key thus Object['key'] where key can be an int or a string or any object

Comments

0

Json objects are perfectly integrated in javascript.

This means that for a definition:

var myObject = { "name": "Doe", "parents": {"father": "Louis", "mother": "Ophelia"}};

You can simply access the data with following statements:

var myName = myObject.name;
var myFather = myObject.parents.father;
var myMother = myObject.parents.mother;

It really is as simple as that.

As an exact answer to your question, it is indeed info.h.

UPDATE: If you mean the h from the info.pf url, that would be

var h = info.pf.substr(info.pf.indexOf("?h=")+3, 999);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.