I want to convert string from koderesult into object, and then thie obj.result should be like this >> obj.GetReportIdResult. on function detail(), koderesult is string, then I want to use this koderesult string for obj object. how to convert the koderesult string to object name?
well, I have obj.GetReportIdResult to get JSON Object, then I want GetReportIdResult is dinamic (e.g. it can change to GetReportMyResult or GetReportHkResult)
here is my function:
function detail(kodenegara, koderesult)
{
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: "http://10.80.3.73/webservice/Service1.svc/json/weeklyflash/"+kodenegara,
dataType: "json",
success:function(data){
var json = JSON.stringify(data);
var obj = JSON.parse(json);
//alert (koderesult);
result = eval(koderesult);
alert( countTypesForBulan(obj.result, "4") ); //this obj.result should be like this >> obj.GetReportIdResult
},
error: function () {
alert("ERROR");
}
});
}
here is the button to call this function:
<button type="button" onclick="detail('id', 'GetReportIdResult')">Display JSON String</button>
Your question is not very clear. But I think what you need is this:
obj.GetReportIdResultis same withobj['GetReportIdResult'].