私はこのJSONのStringBuilder
{
"elements": [{
"company": "Microsoft",
"isValid": "yes"
}, {
"company": "Google",
"isValid": "no"
}, {
"company": "Apple",
"isValid": "yes"
}
]
}
を持っているとのisValidは= yesの場合、それはOKでない場合、私はこの
Microsoft is OK
Google is NOT OK
Apple is OK
のようなものである文字列の出力を構築したいと思います'そうでなければ
ここに私のコード
for (i in result) {
var output = new StringBuilder();
if (result[i].isValid == "yes") {
output.append(result[i].company);
output.append(" is OK\n");
} else {
output.append(result[i].company);
output.append(" is NOT OK\n");
}
}
console.log(output.toString());
しかし、出力は最後のものだけ(AppleがOKである)である 'OK' です。
ループを入力するたびに新しいStringBuilderを作成する必要があるため、あまり効率的ではありません。 – Lapacho
はい!あなたの答えはより最適です。 –