我陷入了这个问题,我正在调用一个 webService,它返回一个 json 响应。
现在我想从该响应中获取特定的值,但在互联网上搜索并努力挣扎后无法修复它。
这是我的代码:
var xhr = Titanium.Network.createHTTPClient({
onload : function(e) {
Ti.API.info("Received text: " + this.responseText);
alert('success');
},
// function called when an error occurs, including a timeout
onerror : function(e) {
Ti.API.debug(e.error);
alert('error');
},
timeout : 5000
});
var data = {"data":"system.connect"};
xhr.open("POST","http://mytesturl.net/services/json");
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
xhr.send("method=system.connect");
响应是这样的:
{"#error":false,"#data":{"sessid":"c4likn6vg33hngbpmobisrsbpcjjmf39","user":{"uid":0,"hostname":"102.119.85.120","roles":{"1":"anonymous user"},"session":"","cache":0}},"#response_code":200}
从上面的回复中我想获取sessid
价值。
什么是正确的做法?