2012-05-28 47 views
0

我有兩個服務器上運行一個應用程序,一個工程,一個不能理解爲什麼。jquery parse json問題

AJAX查詢..

$.ajax({ 
     type: "POST", 
     url: "WebService.asmx/GetFinish1", 
     data: '{' + 
         'Item:"' + item + '"' + 
        '}', 
     contentType: "application/json; charset=utf-8", 
     dataType: "json", 
     success: function (msg) { 
      var data = jQuery.parseJSON(msg); 
      $("#item").val(JSON.stringify(msg)); 

在行$("#item").val(JSON.stringify(msg));從一個我得到...

{"d":"{\"0\":{\"i\":\"MODIFIED C/W TOOL MC WALL\",\"D\":\"Notes\",\"V\":\"MODIFIED C/W TOOL MC WALL\"},\"1\":{\"i\":\"EA\",\"D\":\"Unit\",\"V\":\"EA\"},\"2\":{\"i\":\"EA\",\"D\":\"Unit\",\"De\":\"Unit\",\"V\":\"EA\"}}"} 

第二我得到

"{\"0\":{\"i\":\"1x 8351-3 & 2 x 8352-3\",\"D\":\"Notes\",\"V\":\"1x 8351-3 & 2 x 8352-3\"},\"1\":{\"i\":\"PC3\",\"D\":\"Unit\",\"V\":\"PC3\"},\"2\":{\"i\":\"PC3\",\"D\":\"Unit\",\"De\":\"Unit\",\"V\":\"PC3\"}}" 

第二個作品,第一不,但爲什麼區別?相同的代碼!額外{}和d:來自哪裏?

+0

你肯定兩個服務器都運行相同的代碼? –

+0

你好,我把代碼複製過來了 – Beginner

回答

1

你不需要

var data = jQuery.parseJSON(msg); 
$("#item").val(JSON.stringify(msg)); 

因爲,msg已經JSON格式由於ajax財產使用dataType: 'json'

0

我不知道爲什麼,但我不得不使用下面的var data = jQuery.parseJSON(msg.d);