Reputation: 5571
How can I parse GeoJSON in Android? GeoJSON is an open format for encoding a variety of geographic data structures, based on JSON. A GeoJSON object may represent a geometry, a feature, or a collection of features.
Android has a native org.json package which contains a public class, JSONTokener, that parses a JSON (RFC 4627) encoded string into the corresponding object.
Since every GeoJSON data structure is a JSON object with extra stuff, is it ok to use the native Android JSON package to parse GeoJSON data?
Upvotes: 1
Views: 796
Reputation: 11185
Quoting their documentation
A complete GeoJSON data structure is always an object (in JSON terms). In GeoJSON, an object consists of a collection of name/value pairs -- also called members. For each member, the name is always a string. Member values are either a string, number, object, array or one of the literals: "true", "false", and "null". An array consists of elements where each element is a value as described above.
From that description, you should have no trouble parsing those using the native classes. Since the format is standardized you might also want to look into Google gson as an option. It could save you time.
Upvotes: 2