![]() JSONArray result = CDL.toJSONArray(ja, string) We have an alternative way of doing this where we can achieve the same functionality by supplying a JSONArray to get the headers and a comma delimited String working as the data.Īgain, we separate different lines using a carriage return (\r) or line feed (\n): JSONArray ja = new JSONArray() Notice that both data and header were supplied within the same String. The object JSONArray result now consists of the following (output formatted for the sake of clarity): [ JSONArray result = CDL.toJSONArray(string) The first line is interpreted as a list of headers, and all the subsequent lines are treated as data: String string = "name, city, age \n" This method is overloaded and supports a wide range of data types.įor a complete list of methods supported by JSONArray, visit the official documentation. ![]() put(Object value) – append an object value to this JSONArray.If there's no value at that index, then a null is returned. opt(int index) – returns the value associated with an index (between 0 and total length – 1).get(int index) – returns the value at the specified index (between 0 and total length – 1), otherwise throws a JSONException.These are the primary methods of the JSONArray class: Like JSONObject, it has a constructor that accepts a source String and parses it to construct a JSONArray. ![]() It's represented by a String wrapped within square brackets and consists of a collection of values separated by commas.Values can be anything from a Number, String, Boolean, JSONArray, or JSONObject to even a JSONObject.NULL object.A JSONArray is an ordered collection of values, resembling Java's native Vector implementation.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |