Android Tutorial Android JSON tutorial

Status
Not open for further replies.

bluedude

Well-Known Member
Licensed User
Longtime User
It is valid but I just copied in object arrays. I'm having trouble to determine how to create object arrays [] when needed See for example below:

"total": [
{
"price": 85,
"name": "myname",
"value": "aname"
}
],
"shipping": [
{
"price": 80,
"name": "through",
"value": "empty"
}
]

Can this all be done with arrays and CreateMap?
 

pjetson

Member
Licensed User
Longtime User
If I put a URL into a JSON object from a B4A app, the slashes in the URL are escaped with backslashes.

For example, if I have this URL:

http://maps.google.com/?q=-37.9033777,145.0354729

and put it into a JSON string, it comes out like this:

http:\/\/maps.google.com\/?q=-37.9033777,145.0354729

I can't see anywhere that describes this behaviour - is it part of the JSON standard, or is it a convention to try to stop bad things from happening?
 

little3399

Active Member
Licensed User
Longtime User
Hi, Everyone

Is there a simple way to save json to sqlitedb or json.txt file ?
 

vincentehsu

Member
Licensed User
Longtime User
Can someone point me in a direction of a tutorial that will help me parse this JSON string
B4X:
{"QueryUpdateResult":"[{\"TXNCode\":\"TXN_QUERY_Q001\",\"MerchantID\":\"00000001\",\"MerchantName\":\"Poskitz Ltd\",\"HardwareID\":\"B8:5E:7B:07:43:92\",\"UpdateTime\":\"2015\/1\/16 下午 01:53:56\",\"DeviceUser\":\"Vincent\",\"Version\":\"New 1.0\",\"isSuccees\":\"1\",\"TypeDesc\":\"NewAPP or APPUpdate\",\"MAC\":\"\",\"Message\":\"Success\"},{\"TXNCode\":\"TXN_QUERY_Q001\",\"MerchantID\":\"00000001\",\"MerchantName\":\"Poskitz Ltd\",\"HardwareID\":\"8C:DE:52:6A:18:9F\",\"UpdateTime\":\"2015\/1\/16 下午 01:54:23\",\"DeviceUser\":\"Vincent\",\"Version\":\"V5V7\",\"isSuccees\":\"1\",\"TypeDesc\":\"TerminalUpdate\",\"MAC\":\"\",\"Message\":\"Success\"}]"}
I've try many times but still not get it
 
Last edited:

fishwolf

Well-Known Member
Licensed User
Longtime User
For external reason i can receive a string, but not is my json, for example can be the html with error.

Now my application crashed, i want add a check on json validiation

how to i can validate the json buffer with b4a function?

Thanks
 

Bryanne Vega

Member
Licensed User
Longtime User
Hey Erel, would a tool be considered to be made, just like JsonTree but that does the inverse?
 

engvidal

Member
Licensed User
Longtime User
Hi.
How can I read only the first 'block' of data from a web based json:

http://thethingsnetwork.org/api/v0/nodes/02015510/

Just the 2 first blocks...

[
{
"snr":9.5,
"gateway_eui":"0080000000009F69",
"node_eui":"02015510",
"data_raw":"QBBVAQKAOQA60NlBIuXL8Q==",
"data":"AqBY",
"rssi":-90,
"datarate":"SF7BW125",
"time":"2016-03-02T14:27:48.817Z",
"frequency":902.899963
},
{
"snr":9.3,
"gateway_eui":"0080000000009F69",
"node_eui":"02015510",
"data_raw":"QBBVAFER45aA60NlBIuXL8Q==",
"data":"AqBZ",
"rssi":-92,
"datarate":"SF7BW125",
"time":"2016-03-02T14:27:12.017Z",
"frequency":902.899162
},
.
.
.
]

Thanks
 

DonManfred

Expert
Licensed User
Longtime User
Is not a valid json. Remove the last dots


B4X:
Dim parser As JSONParser
parser.Initialize(<text>)
Dim root As List = parser.NextArray
For Each colroot As Map In root
Dim rssi As Int = colroot.Get("rssi")
Dim data_raw As String = colroot.Get("data_raw")
Dim data As String = colroot.Get("data")
Dim snr As Double = colroot.Get("snr")
Dim node_eui As String = colroot.Get("node_eui")
Dim datarate As String = colroot.Get("datarate")
Dim time As String = colroot.Get("time")
Dim gateway_eui As String = colroot.Get("gateway_eui")
Dim frequency As Double = colroot.Get("frequency")
Next

See http://basic4ppc.com:51042/json/index.html
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…