Skip to content

Commit

Permalink
array新增解析Response
Browse files Browse the repository at this point in the history
  • Loading branch information
TommyLemon committed Jun 11, 2017
1 parent 10cfc9d commit 4cc0be1
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions Demo/GET/array.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<body>
<script >
var json = {
"[]":{
"User[]":{
"count":5,
"page":1,
"User":{
Expand All @@ -17,7 +17,29 @@
}
};

request(url_get, json);
rq = request(url_get, json, false, function () {
if (rq.readyState !== 4) {
return;
}

if (rq.status === 200) {
alert("Response(GET):\n" + format(rq.responseText));

var rp = JSON.parse(rq.responseText);
var arr = rp == null ? null : rp["User[]"]; //取出数组User[]
if (arr != null) {
alert("User[] length = \n" + arr.length);

var user0 = arr == null || arr.length <= 0 ? null : arr[0]; //取出User[]第0项
if (user0 != null) {
alert("User[]/0 = \n" + format(JSON.stringify(user0)));
alert("User[]/0/id = \n" + user0.id); //取出并显示User[]第0项User的id
}
}
} else {
alert("Response(GET):\nstatus" + rq.status + "\nerror:" + rq.error);
}
});
</script>
</body>
</html>

0 comments on commit 4cc0be1

Please sign in to comment.