자바 스크립트 :
function loadDoc(url) {
$.ajax({
url: 'mytestjson',
dataType: 'json',
cache: false
}).success(function (result) {
console.log(result);
//var txt = result.newBranches[0].newNonBranchLocation;
$.each(result.newBranches, function(index, txt)
{
// change this to FALSE when ready
if (newNonBranchLocation.indexOf('TRUE') > -1) {
$('#btbumpin').hide();
}
else {
$('#btbumpin').show();
}
});
})
}
JSON :
{
"errorNode": {
"errorCode": 0,
"errorMsg": "",
"errorSev": ""
},
"newBranches": [{
"cn": "11111101",
"newNonBranchLocation": "TRUE",
"newBranchNumber": "111111"
}, {
"cn": "11111102",
"newNonBranchLocation": "TRUE",
"newBranchNumber": "111111"
}, {
"cn": "11111103",
"newNonBranchLocation": "TRUE",
"newBranchNumber": "111111"
}, {
"cn": "11111181",
"newNonBranchLocation": "TRUE",
"newBranchNumber": "111111"
}]
}
위의 jQuery와 JSON이 있습니다. 내부의 모든 값을 반환하고 싶지만 newBranches
현재 첫 번째 newBranches
개체 의 값만 가져옵니다.
"cn": "11111101",
"newNonBranchLocation": "TRUE",
"newBranchNumber": "111111"
나는 등을 반환 11111101TRUE11111111111102TRUE111111
하고 싶습니다 . 즉 .NET의 모든 값과 연결된 문자열을 반환합니다 newBranches
.
예를 들어 루프 외부에 변수를 선언하십시오.
var output = '';
루프 내에서 필요한 모든 값을 변수에 추가 할 수 있습니다.
output + = txt.cn + txt.newNonBranchLocation + txt.newBranchNumber;
루프가 완료된 후 추가 된 문자열을 포함하는이 변수를 사용할 수 있습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다