• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Reading Json from external file

Community Beginner ,
Aug 16, 2023 Aug 16, 2023

Copy link to clipboard

Copied

This is my Json :

{"MatchOnCourt":{"MatchID":"42959157","Tournament":"Ystad, Singles Qualifying, M-ITF-SWE-03A","P1Name":"ROBIN","P1Surname":"THOUR","P2Name":"OLLE","P2Surname":"NOLTORP","NOC1":"\u0026#160;","NOC2":"\u0026#160;","Score1":"0","Score2":"0","P1s1":"3","P1s2":"0","P1s3":"\u0026#160;","P2s1":"6","P2s2":"1","P2s3":"\u0026#160;","Serve":"1","Time":"00:49:59","Status":"SECOND_SET","CourtID":1,"Sponsor":null,"TournamentGroupID":777,"CourtName":"Court 4","Custom":null,"Info":"Break [T2] (double fault)","SRadarTournamentID":135793,"SRadarCategory":"ITF Men","Order":1}}

 

Code:

	var that = this;
	this.json = {};

	this.loadJson = function(url)
	{

		var queue = new createjs.LoadQueue(true);
		queue.on("fileload", that.onJsonLoaded, that);
		queue.on("error", that.onJsonLoadError, that);
		queue.loadFile({id:"json", src:url});

	}

	this.onJsonLoaded = function(e)
	{	
		that.json = e.target.getResult("json");

		console.log(that.json)
		
		var jMat = that.json.MatchOnCourt;
		
		console.log("0 +++++ " + jMat.Time)	

	}

	this.onJsonLoadError = function(e)
	{
	  console.log(e);
	}

	this.loadJson(URL);

 

What i am trying to do is to read the value time, i can load the Json (beacuse the firs console.log write my all the json file...) but i can not get "Time" value. What am i doing wrong?

 

Thanks 

Views

109

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 16, 2023 Aug 16, 2023

Copy link to clipboard

Copied

I find the problem.... i missed parsing to Json ... ( var jMat = JSON.parse(that.json); )

 

stupid error...

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 16, 2023 Aug 16, 2023

Copy link to clipboard

Copied

LATEST

for others, this may make more sense:

 

loadJasonF.bind(this)("json_id.json");
 
function loadJasonF (url){
var queue = new createjs.LoadQueue(true);
queue.addEventListener("fileload", jasonLoadedF.bind(this));
queue.addEventListener("error", jasonLoadErrorF.bind(this));
queue.loadFile({
id: "json",
src: url
});
}
 
function jasonLoadedF(e){
this.json = e.target.getResult("json");
this.data = this.json.data;
textF.bind(this)();
}
 
function jasonLoadErrorF(e){
console.log(e);
}
function textF(){
for (var i = 0; i < this.data.length; i++){
this.txt.text = this.txt.text + "\n" + this.data[i].id + ", " + this.data[i].name + ", " + this.data[i].class +", " + this.data[i].mark + ", " + this.data[i].sex;
}
}
 
/////////////////////////////////////////////
where json_id.json contains
 

{
"data":
[
{"id":"1","name":"John Deo","class":"Four5",
"mark":"75","sex":"male"},

{"id":"2","name":"Max Ruin","class":"Three5",
"mark":"85","sex":"male"},

{"id":"3","name":"Arnold","class":"Three5",
"mark":"55","sex":"male"},

{"id":"4","name":"Krish Star","class":"Four5",
"mark":"60","sex":"male"}
]
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines