Getting content from JSON string

I am currently developing an Android application which has a web backend. I can receive a JSON file which looks like the following:

[{"Latitude":"53.4041999","lontitude":"-6.377542"}]

I'm trying to figure out how to get the two coordinates from the JSON files and use them for mapping positions. Does anyone have any ideas how to get the two coordinates from the JSON file as doubles?

Answers


JSONObject jObject = new JSONObject(response);
double lat = jObject.getDouble("Latitude");
double lng = jObject.getDouble("lontitude");

What you need to do is create JSONObject and just get double values using getDouble(name);

Edit: Either create JSONArray(see @Glenn.nz comment below) or just do JSONObject jObject = new JSONObject(response.substring(1, response.lenth()-1));


Need Your Help

Why does GCC drop the frame pointer on 64-bit?

gcc assembly

What's the rationale behind dropping the frame pointer on 64-bit architectures by default? I'm well aware that it can be enabled but why does GCC disable it in the first place while having it enabl...

Git - Accidentally Overwrote Entire Commit History of Remote Repository

svn git git-svn

In an attempt to create a bridge between Git and SVN that allows developers on one project to use SVN and those on another project to use Git, I inadvertantly overwrote the entire git commit histor...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.