Android Question Need help extracting data

tsteward

Well-Known Member
Licensed User
Longtime User
I'm hoping someone can help me get this data into an array or import into a sql table.
Each record starts and ends with {}
Before the : is field name and data comes after the : and the each field is comma seperated.

 

BillMeyer

Well-Known Member
Licensed User
Longtime User
Hi there,

It seems to me that the data is in JSON format. That is quite easy to parse. Here is the code:

Parse Code for JSON Text:
Dim parser As JSONParser
parser.Initialize(<text>)
Dim root As Map = parser.NextObject
Dim list As List = root.Get("list")
For Each collist As Map In list
 Dim chip_type As String = collist.Get("chip_type")
 Dim modulation As String = collist.Get("modulation")
 Dim is_verify As Int = collist.Get("is_verify")
 Dim kdno As String = collist.Get("kdno")
 Dim column_name As String = collist.Get("column_name")
 Dim description As String = collist.Get("description")
 Dim fccid As String = collist.Get("fccid")
 Dim type As Int = collist.Get("type")
 Dim bin_md5 As String = collist.Get("bin_md5")
 Dim update_date As String = collist.Get("update_date")
 Dim frequency As Int = collist.Get("frequency")
 Dim sub_type As String = collist.Get("sub_type")
 Dim outside_view As String = collist.Get("outside_view")
 Dim id As Int = collist.Get("id")
 Dim sample_provider As String = collist.Get("sample_provider")
 Dim is_anti_theft As Int = collist.Get("is_anti_theft")
 Dim partno As String = collist.Get("partno")
Next
Dim status As Int = root.Get("status")

This is how I did it:

1. Copy the text (or JSON) you have given in your post.
2. Go to this tool http://www.b4x.com:51042/json/index.html and use it to get the code listed above.

Now we need some more information about your SQL before we can help there. We need to know - SQLite, MySQL, MSSQL, is your database online, are you using php or jRDC2 to manipulate it etc.

I trust the above will go some way in helping.
 
Upvote 0

BillMeyer

Well-Known Member
Licensed User
Longtime User
My my - you guys are quick !!
Maybe my age is catching up now !!
 
Upvote 0

tsteward

Well-Known Member
Licensed User
Longtime User
ok so need more help if you guys have time.
Firstly I know this is the android thread and the attached code is B4J. I wasn't thinking but this data is for my android app only I manipulate the data on my PC.

Now the json strings are in the KDEntities.db file.
I want to extract the contents from the Table "Remote" and split it int records in my Helper.db table KeyDiy.

If you look at the code I think you will see what I am trying to do.
I can't seem to create the list from the json string I THINK.....
 

Attachments

  • kdimporter.zip
    350.6 KB · Views: 250
Upvote 0

roerGarcia

Active Member
Licensed User
Longtime User
The error is in the variables names. I added the QUOTE function around the text values. Check the names carefully.

B4X:
laraSQL.ExecNonQuery("INSERT INTO KeyDiy VALUES( " & id & ", " & QUOTE & chip_type & QUOTE & ", " & QUOTE & modulation & QUOTE & ", " & QUOTE & is_verify & QUOTE & ", " & QUOTE & kdno & QUOTE & ", " & QUOTE & column_name & QUOTE & ", " & QUOTE & description & QUOTE & ", " & QUOTE & fccid & QUOTE & ", " & rType & ", " & frequency & ", " & QUOTE & sub_type & QUOTE & ", " & QUOTE & outside_view & QUOTE & ", " & is_anti_theft & ", " & QUOTE & partno & QUOTE & ")")

INSERT INTO KeyDiy VALUES( 4599, "", "", "2", "SONATA", "Sonata", "REPLACE USE FOR PN:95430 3K001
MUST USE B02 REMOTE TO MAKE
THANKS ANDY PROVIDE INFO", "", 1, 447, "B SERIES OR NB Multifunction", "https://ovs.keydiy.com/rmts/168f9ddf264a005d8b568b73e1872b98/94ec17d7c095fc621cca983ca80ce006.png", 2, "SONATA")
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…