Android: How to parse JSON file with Gson Library?

How does a web page interact with a server to parse a dynamic JSON file?

  • Trying to identify what knowledge I am missing here. So that I know what tutorials to looks for. My goal is to have a page load dynamic content into a web page from a JSON file. I  already set up the templating system using MustacheJS. I know how to  work with JSON, and my page works fine. But I am trying to find the best ways to scale this app. Currently this my method is inefficient, I am hand coding all of the JSON, and creating it for 60+ entries (store locations), so far I am up to 4... So I am guessing that I would need to work with a database and then have  JavaScript interact with that database. But what what am I missing  here? Would there be a database (SQLite3, CouchDB, etc?) that is best for this? All the results that I am getting on Google and YouTube (about JSON) are just "this is what JSON is and this is how you write a JSON file." So terms that I should be familiar with so I can have a more relevant search are appreciated as well.

  • Answer:

    It's going to depend a lot on what you have technology-wise on the ...

Ryan Kennedy at Quora Visit the source

Was this solution helpful to you?

Other answers

"My goal is to have a page load dynamic content into a web page from a JSON file" This part of the question is unclear. If I understand you correctly, you would like to store some content in a database. When it comes time to display that data on a web browser, you will need to : 1. Read that data from a database (anyone will do) in a web-server/application-server using your language of choice (e.g. Java running in a servlet engine like Tomcat/Jetty) 2. Convert that data in to a JSON stream in the code and send it as a HTTP response (text/json) to the browser where your MustacheJS code is running. No explicit JSON file is needed. Depending on your language of choice, you will need : 1. Some code to read/write to a database (in Java, check out Spring JDBC and just plain Java JDBC) 2. Some code to create a JSON stream (in Java, check out the Jackson library) Every language has specific libraries to solve the 2 problems above. For example,http://www.json.org/ lists JSON parser/serialization support in many languages.

Siddharth Anand

If you're only dealing with 60 records there's no need to add a full database. I've actually hand coded a 50 record JSON file before and it was fine- use an editor with good JSON support (I like Sublime Text 2) and it's pretty easy to hand write. Another option that might work well for this particular situation is to put the data in a Google Docs spreadsheet, which will then be able to produce JSON for you automatically: see https://developers.google.com/gdata/samples/spreadsheet_sample

Simon Willison

What backend and database solution you choose really depends on what you know or are comfortable getting to know. As already stated by 1st answer, there's native or plugin support for serializing backend objects to JSON for most languages these days. For example, PHP has a native function called: "json_encode()". For a full-stack JavaScript approach, you can use MongoDB, Node.js and Mustache. Mongo stores objects in JSON. There's no one stack selection to rule them all, really. You just need a place to store you objects (database), a backend that can call the database, JSON encode the data and serve it up via HTTP and your JavaScript in the client to perform an AJAX call to retrieve the JSON, parse it and finally render it.

Keith Daulton

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.