koderesult
文字列をオブジェクトに変換したいのですが、次obj.result
のようにする必要があります >> obj.GetReportIdResult
. functiondetail()
で、が文字列の場合、この文字列をオブジェクトkoderesult
に使用したいと考えています。文字列をオブジェクト名に変換する方法は?
さて、私はJSONオブジェクトを取得する必要があります。次に、ダイナミックが必要です(たとえば、 orに変更できます)ここに私の関数があります:koderesult
obj
koderesult
obj.GetReportIdResult
GetReportIdResult
GetReportMyResult
GetReportHkResult
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");
}
});
}
この関数を呼び出すボタンは次のとおりです。
<button type="button" onclick="detail('id', 'GetReportIdResult')">Display JSON String</button>