Java Android How to build a random database?

Asked

Viewed 35 times

-1

In the Android app, using Java, I get a Json string that looks like this:

String teste = "{\n" + " \"nometabela\":{\n" + " \"id\":\"f83d6101cc\",\n" + " \"coluna1\":\"codigo\",\n" + " \"coluna2\":\"descricao\",\"coluna3\":\"quantidade\"\n" + " }

With this data, I need to create the database using Sqlite. For example, the given "table name" within the Json string will have to be the table name, the "id" will be "f83d6101cc", the name of the first column will be "code", the second "description" and the third "quantity".

With the fixed data, I was able to create the database.

However, the data won’t always look like this. I’ll never know what this Json file looks like. The database created will have to be based on it, so there may be more columns, or fewer columns, etc.

How do I read this String Json and create a database according to the values passed by it? Thank you.

1 answer

0

You can make your code recognize that each " : "passed by Json means a new column. And whatever is left of those dots means the name of the table, and the right its contents.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.