JSON Object return undefined?

Tanya von Degurechaff

This array.

var theObject = [{"id":"412","thn_akademik":"20152","id_prodi":"15301","kode_mk":"20038","tanggal":"23\/8\/2016","jam_1":"17:00\t","jam_2":"19:00\t","npm":"07150100190","flag1":"0","flag2":"0"},{"id":"558","thn_akademik":"20152","id_prodi":"15301","kode_mk":"20053","tanggal":"25\/8\/2016","jam_1":"17:00\t","jam_2":"19:00\t","npm":"07150100190","flag1":"0","flag2":"0"},{"id":"704","thn_akademik":"20152","id_prodi":"15301","kode_mk":"20052","tanggal":"30\/8\/2016","jam_1":"17:00\t","jam_2":"19:00\t","npm":"07150100190","flag1":"0","flag2":"0"},{"id":"850","thn_akademik":"20152","id_prodi":"15301","kode_mk":"000047","tanggal":"31\/8\/2016","jam_1":"17:00\t","jam_2":"19:00\t","npm":"07150100190","flag1":"0","flag2":"0"},{"id":"996","thn_akademik":"20152","id_prodi":"15301","kode_mk":"20050","tanggal":"23\/8\/2016","jam_1":"09:00\t","jam_2":"11:00\t","npm":"07150100190","flag1":"0","flag2":"0"},{"id":"1142","thn_akademik":"20152","id_prodi":"15301","kode_mk":"20051","tanggal":"25\/8\/2016","jam_1":"09:00\t","jam_2":"11:00\t","npm":"07150100190","flag1":"0","flag2":"0"},{"id":"1288","thn_akademik":"20152","id_prodi":"15301","kode_mk":"000030","tanggal":"30\/8\/2016","jam_1":"09:00\t","jam_2":"11:00\t","npm":"07150100190","flag1":"0","flag2":"0"}] ;


for (var i = 0; i < theObject.length; i++) { 
    alert(theObject[i].kode_mk);
}

It works when i test in on fiddle.

But when i try in on my apps in return undefined.

anyone know what make this happen?

James111

This is a javascript object NOT a JSON object. It's not clear what you're asking "But when i try in on my apps in return undefined.". What app?

If your app is retrieving JSON, you must parse it before trying to loop through it. E.g

var json = JSON.parse(JSON_HERE); 

You can then loop through that json object and retrieve the kode_mk.

If you have code from your "app", please provide it. Tell us what your app is doing and how it's getting the JSON

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related