React Native
React Native
Load a JSON Array
See more JSON Examples
The Chilkat JSON API requires the top-level JSON to be an object. Therefore, to load an array requires that it first be wrapped as an object.Chilkat React Native Downloads
import { JsonObject, StringBuilder } from '@chilkat/react-native'
function chilkatExample() {
// Imagine we want to load this JSON array for parsing:
const jsonArrayStr = '[{"id":200},{"id":196}]';
// First wrap it in a JSON object by prepending "{ "array":" and appending "}"
const sbJson = new StringBuilder();
sbJson.append('{"array":');
sbJson.append(jsonArrayStr);
sbJson.append('}');
const json = new JsonObject();
json.load(sbJson.getAsString());
// Now we can get the JSON array
const jArray = json.arrayAt(0);
// Do what you want with the JSON array...
// For example:
const jObjId = jArray.objectAt(0);
console.log(jObjId.intOf('id'));
}