Файлы JSON можно получить через XHR, установив тип ответа на «json». Таким образом, результатом будет объект JSON. Ниже фрагмент код в качестве примера:
<script>
// Set url
var jsonUrl = 'myJson.json';
// Call WinJS.xhr to retrieve a json file
WinJS.xhr({
url: jsonUrl,
responseType: "json"
// https://msdn.microsoft.com/en-us/library/windows/apps/br229787.aspx
// json: The type of response is String. This is used to represent JSON strings. responseText is also of type String, and responseXML is undefined.
// Note As of Windows 10, when responseType is set to json, the responseText is not accessible and the response is a JavaScript object. Behavior on Windows 8.1 and earlier remains as described above.
}).done(
// When the result has completed, check the status.
function completed(result) {
if (result.status === 200) {
// Get the XML document from the results.
console.log(result);
var jsonFileContent = result.response; // returns an object
console.log(jsonFileContent);
console.log(jsonFileContent.rabbits[0].name);
/* The content of file: myJson.json
{
"rabbits":[
{"name":"Jack", "age":3},
{"name":"Mac", "age":4},
{"name":"Hanna", "age":2}
]
}
*/
}
});
</script>
Не мог бы вы показать код, особенно если вы пытаетесь изменить объект –
я не написал ни одной строки коды для этого еще =/Так как связанные коды не работают , У меня нет абсолютно никакой идеи, что делать. Извините ... Автозаполнение показывает, что вы можете использовать пространство имен Windows.Data.Json, вот что я пытаюсь искать сейчас. –
Являются ли файлы, которые вы пытаетесь загрузить в своем пакете (в вашем проекте) или где-то еще? –