簡體   English   中英

從 http 響應正文中獲取特定值

[英]Getting specific value from http response body

我無法從 http 響應正文中獲取值。

我在 response.body 上使用了JSON.parse()以及xml-js庫。 我必須得到的值是“ P01 ”。 這是回應:

{  
   "Soap:Envelope":{  
      "_attributes":{  
         "xmlns:Soap":"http://schemas.xmlsoap.org/soap/envelope/"
      },
      "Soap:Body":{  
         "ValidateUser_Result":{  
            "_attributes":{  
               "xmlns":"urn:microsoft-dynamics-schemas/codeunit/UserValidation"
            },
            "return_value":{  
               "_text":"P01"
            }
         }
      }
    }
}

這是我嘗試過的:

console.log(JSON.parse(data["Soap:Envelope"]["Soap:Body"]["ValidateUser_Result"]["return_value"])));
var o = {  
   "Soap:Envelope":{  
      "_attributes":{  
         "xmlns:Soap":"http://schemas.xmlsoap.org/soap/envelope/"
      },
      "Soap:Body":{  
         "ValidateUser_Result":{  
            "_attributes":{  
               "xmlns":"urn:microsoft-dynamics-schemas/codeunit/UserValidation"
            },
            "return_value":{  
               "_text":"P01"
            }
         }
      }
    }
};

var val = o['Soap:Envelope']['Soap:Body']['ValidateUser_Result']['return_value']['_text'];

console.log(val);

這將解決問題。

 const data = { "Soap:Envelope":{ "_attributes":{ "xmlns:Soap":"http://schemas.xmlsoap.org/soap/envelope/" }, "Soap:Body":{ "ValidateUser_Result":{ "_attributes":{ "xmlns":"urn:microsoft-dynamics-schemas/codeunit/UserValidation" }, "return_value":{ "_text":"P01" } } } } } console.log(data["Soap:Envelope"]["Soap:Body"]["ValidateUser_Result"]["return_value"]["_text"]);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM