国に基づいた言語を取得するためにサービスを呼び出しています。複数の言語を返す場合、次のコードは正常に機能しています。ただし、1つのレコードのみを返す場合、出力は正しく行われません(「未定義」として表示されます。アドバイスをお願いします。
これが私のコードです:
$.ajax({
type: 'POST',
url: "http://mymethod",
complete: function () { $.mobile.hidePageLoadingMsg(); },
dataType: "json",
contentType: 'application/json',
data: JSON.stringify({
"country": countryCode
}),
success: function (output, textStatus, jqXHR) {
$.each(output.geographyInfo, function (i, theItem) {
try {
languages.push("<option value='" + theItem.languageCode + "'>" + theItem.languageName + "</option>");
}
catch (error) {
alert(error);
}
});
$(languages.join('')).appendTo("#dpdLanguages").trigger("create");
}
});
これがjsonの出力です。
これは、1つの言語のみの場合の出力です。
{"geographyInfo":{"active": "true"、 "countryCode": "US"、 "countryName": "UNITED STATES"、 "instanceID": "1"、 "languageCode": "EN"、 "languageName" :"English"、 "regionName": "North America"}、 "reasonDetails":null、 "size": "1"、 "status": "true"}
そして複数の場合
{"geographyInfo":[{"active": "true"、 "countryCode": "CA"、 "countryName": "CANADA"、 "instanceID": "1"、 "languageCode": "EN"、 "languageName" :"English"、 "regionName": "North America"}、{"active": "true"、 "countryCode": "CA"、 "countryName": "CANADA"、 "instanceID": "1"、 "languageCode ":" FR "、" languageName ":" French "、" regionName ":" North America "}、{" active ":" true "、" countryCode ":" CA "、" countryName ":" CANADA "、" instanceID ":" 2 "、" languageCode ":" EN "、" languageName ":"英語 "、"regionName ":" Americas "}、{" active ":" true "、" countryCode ":" CA "、" countryName ":" CANADA "、" instanceID ":" 2 "、" languageCode ":" FR "、" languageName ":" French "、" regionName ":" Americas "}]、" reasonDetails ":null、" size ":" 4 "、" status ":" true "}
はいudidu、私はそれが事実だと思います..しかし、これを解決する方法は?