I'm creating some code and I saw an example here on this forum, and I have a hard time using geojson.
Whenever it is giving an error in raw because I did not add this json_template
private String getGeoString() throws IOException{
InputStream is = getResources().openRawResource(R.raw.json_template);
Writer writer = new StringWriter();
char[] buffer = new char [1024];
try{
Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
int n;
while ((n= reader.read(buffer)) != -1){
writer.write(buffer, 0, n);
}
}finally {
is.close();
}
String jsonString = writer.toString();
return jsonString();
}
How can I solve this error?
If you would like to create a json file in your app, you can first create a
json_template.json
file in your app -> res -> raw folder.In that file, you can put the entire json response received upon querying.
A useful tool to see the json traversal in the nested response is JSON Pretty Print.
Then you can try:
It should work. Hope this is helpful.