如何获得JSON休息响应 - Node.js的
问题描述:
我怎样才能在下列情况下,JSON对象:如何获得JSON休息响应 - Node.js的
这里是我的POST请求:data.toString的
var articles = client.post("http://host:port/path", args, function (data, response) {
// console.log(xml.parseBuffer(data))
console.log(data.toString('utf8'));
// return xml.parseBuffer(data);
});
结果( 'UTF-8' )看起来像:
<WebServiceResponse>
<page>
...
</page>
<articleDataList>
<articleId>
<idArticle>100000</idArticle>
<index>test</index>
</articleId>
<goodType>test</goodType>
<idAttributeSubject>100001</idAttributeSubject>
<identyfiable>false</identyfiable>
<isActive>true</isActive>
<isGoodSet>false</isGoodSet>
<longName>test</longName>
<translationSubjectId>
<idTranslationSubject>100408</idTranslationSubject>
</translationSubjectId>
<unitCode>szt</unitCode>
<vatRate>0.2300</vatRate>
</articleDataList>
<articleDataList>
...
</articleDataList>
<articleDataList>
...
和xml.parseBuffer(数据)外观: {名称:“articleD ataList',childs:[Object]},
我需要把文章对象只用:idArticle,index和shortName 有什么简单的方法吗?
答
在此输出:
{ name: 'articleDataList', childs: [Object] }
Object
表示你需要字符串化这样的JavaScript对象:JSON.stringify(Object)
或者你应该首先这整个缓冲区转换为字符串,然后转换成JSON或JavaScript对象:
xml.parseString(data.toString('utf8'))
不行,你能解释一下吗? – tyskocz