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.

{"status":0,"list":[{"id":6267,"partno":"DAIHATSU","kdno":"DAIHATSU","type":2,"frequency":309,"modulation":"","chip_type":"","fccid":"","description":"","column_name":"","is_verify":1,"sample_provider":"","outside_view":"https://ovs.keydiy.com/rmts/a8bd083...990.png?rkey=e4c4634d662ca742dcb84aceaba6cb11","update_date":"2018-08-24 23:09:15","bin_md5":"","sub_type":"B SERIES OR NB Multifunction","is_anti_theft":2},{"id":4869,"partno":"DASHISU 312","kdno":"DASHISU 312","type":1,"frequency":312,"modulation":"","chip_type":"","fccid":"","description":"1) Close all door ignition off\r\n2) disconnect battery wait 20 second and connect back\r\n3) press any remote unlock button for 5 second \r\n4) car will auto lock & unlock \r\n5) within 5 second press unlock button again for 1 second untill car auto lock & unlock respond \r\n6) repeat for all remote \r\n7) open door strat engine to exit","column_name":"","is_verify":2,"sample_provider":"","outside_view":"https://ovs.keydiy.com/rmts/95f20b3...33c.png?rkey=e4c4634d662ca742dcb84aceaba6cb11","update_date":"2018-08-24 23:09:06","bin_md5":"83eba1c2a37d20c81e2b78a6605cebbe","sub_type":"B SERIES OR NB Multifunction","is_anti_theft":2},{"id":5184,"partno":"2 button remote 312mhz","kdno":"2 button remote","type":1,"frequency":312,"modulation":"","chip_type":"","fccid":"","description":"","column_name":"","is_verify":2,"sample_provider":"","outside_view":"https://ovs.keydiy.com/rmts/8951cd0...fa1.png?rkey=e4c4634d662ca742dcb84aceaba6cb11","update_date":"2018-08-24 23:09:09","bin_md5":"aefab61935c445a10a8c6e40ae298de7","sub_type":"B SERIES OR NB Multifunction","is_anti_theft":2},{"id":6755,"partno":"DAIHATSU 312.10","kdno":"DAIHATSU 312.10","type":1,"frequency":312.1,"modulation":"ASK","chip_type":"","fccid":"","description":"","column_name":"","is_verify":2,"sample_provider":"","outside_view":"https://ovs.keydiy.com/rmts/cc151f7...4e5.png?rkey=e4c4634d662ca742dcb84aceaba6cb11","update_date":"2019-05-09 19:00:26","bin_md5":"3b3ec0eff60218016113787ae63e107a","sub_type":"B SERIES OR NB Multifunction","is_anti_theft":2},{"id":5155,"partno":"2008DJ1567","kdno":"2008DJ1567","type":2,"frequency":433,"modulation":"","chip_type":"","fccid":"","description":"WORK FOR 2008DJ1567","column_name":"","is_verify":1,"sample_provider":"","outside_view":"https://ovs.keydiy.com/rmts/7fac9c4...7e9.png?rkey=e4c4634d662ca742dcb84aceaba6cb11","update_date":"2018-08-24 23:09:09","bin_md5":"","sub_type":"B SERIES OR NB Multifunction","is_anti_theft":2}]}
 

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

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: 139
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

DonManfred

Expert
Licensed User
Longtime User
Much better would be to use Parametrized queries. No need to use quotes and concatenation at all.
 
Upvote 0
Top