-5

koderesult文字列をオブジェクトに変換したいのですが、次obj.resultのようにする必要があります >> obj.GetReportIdResult. functiondetail()で、が文字列の場合、この文字列をオブジェクトkoderesultに使用したいと考えています。文字列をオブジェクト名に変換する方法は? さて、私はJSONオブジェクトを取得する必要があります。次に、ダイナミックが必要です(たとえば、 orに変更できます)ここに私の関数があります:koderesultobjkoderesult
obj.GetReportIdResultGetReportIdResultGetReportMyResultGetReportHkResult

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>
4

1 に答える 1

1

あなたの質問はあまり明確ではありません。しかし、私はあなたが必要とするのはこれだと思います:

 alert( countTypesForBulan(obj[koderesult], "4") );

obj.GetReportIdResultと同じobj['GetReportIdResult']です。

于 2012-07-04T05:34:32.813 に答える