Ask a question about JSON

Post Reply
User avatar
yzsdn
Posts: 2
Joined: Tuesday 28th July 2020 11:39pm

Ask a question about JSON

Post by yzsdn » Wednesday 29th July 2020 12:00am

Image


As shown in the figure, how can I get this mame value?

Hope to give someone a :cry:

User avatar
Quincunxian
Posts: 89
Joined: Sunday 25th June 2017 12:14am
Location: Western Australia

Re: Ask a question about JSON

Post by Quincunxian » Wednesday 29th July 2020 1:25am

Hi yzsdn
Make sure your project has the gb.web component ticked.
This component has the JSON & JSONCollection classes that you will require.

You can find an introduction to JSON Collections Here

Below is a piece of example code that I use to get JSON results for a Book search from Google Books.
It will work much the same way but you will need to change the format to suit the JSON format of the results in your example.
ie: For Each JSonData["songs"]...

I use a WebView control to get the data by setting the URL field to the search string with the API Key ( assume you have one as well)
Once the data is returned, the WebView.Text will contains the JSON data
Private Sub GetSearchResults()
  Dim JSonData As New Collection
  Dim TmpInt As Integer = 0
  Dim TmpJson As Collection
  Dim RowNo As Integer = 0
  Dim TmpStr As String
  Dim TmpAuthor As String[]

  JSonData = JSON.Decode(WebView1.Text, True)
  If IsNull(JSonData) Then
    Message("Your search [" & AG.APISearchText & "] returned no data")
  Else
        For Each JSonData["items"]
          Grd_Results.Rows.Count = RowNo + 1
          TmpJson = JSonData["items"][RowNo]["volumeInfo"]
          Grd_Results[RowNo, 0].Text = Str(RowNo + 1)
          Grd_Results[RowNo, 1].Text = JSonData["items"][RowNo]["volumeInfo"]["title"]
          TmpAuthor = JSonData["items"][RowNo]["volumeInfo"]["authors"]
          For Each TmpStr In TmpAuthor
            Grd_Results[RowNo, 2].Text = TmpStr & " "
          Next
          Grd_Results[RowNo, 3].Text = JSonData["items"][RowNo]["volumeInfo"]["publishedDate"]
          Grd_Results[RowNo, 4].Text = JSonData["items"][RowNo]["volumeInfo"]["publisher"]
          Inc RowNo
        Next

  Endif

End
Note#
Grd_Results is a standard Gridview control.
AG.APISearchText is a global string value used to pass the search text between forms.

This should give you enough information to decode your JSON results - It may take a bit of trial and error.

Hope this helps.
Cheers - Quin.
I code therefore I am

User avatar
Quincunxian
Posts: 89
Joined: Sunday 25th June 2017 12:14am
Location: Western Australia

Re: Ask a question about JSON

Post by Quincunxian » Wednesday 29th July 2020 1:34am

Here is an partial example of the search results for a book called Gullivers Travels

{
"kind": "books#volumes",
"totalItems": 41,
"items": [
{
"kind": "books#volume",
"id": "9XBtCwAAQBAJ",
"etag": "EHIKp6yCh4E",
"selfLink": "https://www.googleapis.com/books/v1/vol ... AAAAAAAAAA",
"volumeInfo": {
"title": "Gullivers Travels",
"subtitle": "Class Ix",
"authors": [
"Jonathan Swift"
],
"publisher": "Prabhat Prakashan",
"publishedDate": "1938-01-01",
"description": "Jonathan Swift’s satirical novel was first published in 1726, yet it is still valid today. Gulliver’s Travels describes the four fantastic voyages of Lemuel Gulliver, a kindly ship’s surgeon. Swift portrays him as an observer, a reporter, and a victim of circumstance. His travels take him to Lilliput where he is a giant observing tiny people. In Brobdingnag, the tables are reversed and he is the tiny person in a land of giants where he is exhibited as a curiosity at markets and fairs. The flying island of Laputa is the scene of his next voyage. The people plan and plot as their country lies in ruins. It is a world of illusion and distorted values. The fourth and final voyage takes him to the home of the Houyhnhnms, gentle horses who rule the land.",
"industryIdentifiers": [
{
"type": "ISBN_13",
"identifier": "9789351864127"
},
{
"type": "ISBN_10",
"identifier": "935186412X"
}
],
"readingModes": {
"text": true,
"image": true
},
"pageCount": 312,
"printType": "BOOK",
"categories": [
"Comics & Graphic Novels"
],
"maturityRating": "NOT_MATURE",
"allowAnonLogging": false,
"contentVersion": "0.2.2.0.preview.3",
"panelizationSummary": {
"containsEpubBubbles": false,
"containsImageBubbles": false
},
"imageLinks": {
"smallThumbnail": "http://books.google.com/books/content?i ... ce=gbs_api",
"thumbnail": "http://books.google.com/books/content?i ... ce=gbs_api"
},
"language": "en",
"previewLink": "http://books.google.com.au/books?id=9XB ... ce=gbs_api",
"infoLink": "https://play.google.com/store/books/det ... ce=gbs_api",
"canonicalVolumeLink": "https://play.google.com/store/books/det ... BtCwAAQBAJ"
},
.....
Cheers - Quin.
I code therefore I am

User avatar
yzsdn
Posts: 2
Joined: Tuesday 28th July 2020 11:39pm

Re: Ask a question about JSON

Post by yzsdn » Wednesday 29th July 2020 2:31am

Quincunxian wrote:
Wednesday 29th July 2020 1:34am
Here is an partial example of the search results for a book called Gullivers Travels

{
"kind": "books#volumes",
"totalItems": 41,
"items": [
{
"kind": "books#volume",
"id": "9XBtCwAAQBAJ",
"etag": "EHIKp6yCh4E",
"selfLink": "https://www.googleapis.com/books/v1/vol ... AAAAAAAAAA",
"volumeInfo": {
"title": "Gullivers Travels",
"subtitle": "Class Ix",
"authors": [
"Jonathan Swift"
],
"publisher": "Prabhat Prakashan",
"publishedDate": "1938-01-01",
"description": "Jonathan Swift’s satirical novel was first published in 1726, yet it is still valid today. Gulliver’s Travels describes the four fantastic voyages of Lemuel Gulliver, a kindly ship’s surgeon. Swift portrays him as an observer, a reporter, and a victim of circumstance. His travels take him to Lilliput where he is a giant observing tiny people. In Brobdingnag, the tables are reversed and he is the tiny person in a land of giants where he is exhibited as a curiosity at markets and fairs. The flying island of Laputa is the scene of his next voyage. The people plan and plot as their country lies in ruins. It is a world of illusion and distorted values. The fourth and final voyage takes him to the home of the Houyhnhnms, gentle horses who rule the land.",
"industryIdentifiers": [
{
"type": "ISBN_13",
"identifier": "9789351864127"
},
{
"type": "ISBN_10",
"identifier": "935186412X"
}
],
"readingModes": {
"text": true,
"image": true
},
"pageCount": 312,
"printType": "BOOK",
"categories": [
"Comics & Graphic Novels"
],
"maturityRating": "NOT_MATURE",
"allowAnonLogging": false,
"contentVersion": "0.2.2.0.preview.3",
"panelizationSummary": {
"containsEpubBubbles": false,
"containsImageBubbles": false
},
"imageLinks": {
"smallThumbnail": "http://books.google.com/books/content?i ... ce=gbs_api",
"thumbnail": "http://books.google.com/books/content?i ... ce=gbs_api"
},
"language": "en",
"previewLink": "http://books.google.com.au/books?id=9XB ... ce=gbs_api",
"infoLink": "https://play.google.com/store/books/det ... ce=gbs_api",
"canonicalVolumeLink": "https://play.google.com/store/books/det ... BtCwAAQBAJ"
},
.....

I have found a suitable solution, but thank you, I will quote your reference in the future :D

Post Reply