Json array question
Posted: Sat Oct 24, 2020 11:06 am
				
				Hi all,
I am new to JSON and am having difficulty figuring out how to grab the information from an array[object]
e.g. genres

I can grab the title, imdb_id etc. with the following code. But struggling with the array side. I have gone through dozens of JSON topics on this board but still not much wiser 
I would appreciate it if someone could give me some pointers.
thanks
			I am new to JSON and am having difficulty figuring out how to grab the information from an array[object]
e.g. genres

Code: Select all
{"adult":false,"backdrop_path":null,"belongs_to_collection":null,"budget":0,"genres":[{"id":18,"name":"Drama"}],"homepage":null,"id":600635,"imdb_id":"tt0009029","original_language":"en","original_title":"The Eagle's Eye","overview":"Silent film serial","popularity":0.676,"poster_path":"/5XGJX5ErUemM0zBoHj8BOrfV5AP.jpg","production_companies":[{"id":58028,"logo_path":null,"name":"Wharton","origin_country":""}],"production_countries":[{"iso_3166_1":"US","name":"United States of America"}],"release_date":"1918-03-27","revenue":0,"runtime":null,"spoken_languages":[],"status":"Released","tagline":"","title":"The Eagle's Eye","video":false,"vote_average":0.0,"vote_count":0}Code: Select all
InitNetwork()
Structure JSONStructure
  adult.i
  backdrop_path.s
  ;belongs_to_collection.s
  budget.i
  ;List genres.s()
  homepage.s
  id.i
  imdb_id.s
  original_language.s
  original_title.s
  overview.s
  ;popularity.i
  poster_path.s
  ;List production_companies.s()
  ;List production_countries.s()
  ;release_date.s
  revenue.i
  ;Runfor.i
  ;spoken_languages.s
  status.s
  tagline.s
  title.s
  ;video.i
  ;vote_average.i
  ;vote_count.i
 EndStructure
Structure genres
  id.i
  name.s
 EndStructure
    
Define ReturnValue.s
Define Buffer, Size
Define Movie.i = 600635
Define ApiKey.s = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
Buffer = ReceiveHTTPMemory("http://api.themoviedb.org/3/movie/"+Str(Movie)+"?api_key=" + ApiKey + "&language=en-US")
If Buffer
  Size = MemorySize(Buffer)
  ReturnValue = PeekS(Buffer, Size, #PB_UTF8)
EndIf
Debug ReturnValue
JSON = ParseJSON(#PB_Any, ReturnValue)
Define JM.JSONStructure
Define JM2.genres
If JSON
  ExtractJSONStructure(JSONValue(JSON), @JM, JSONStructure)
  ;ExtractJSONList(JSONValue(JSON),genre())
  Debug JM\title
  Debug JM\imdb_id
  FreeJSON(JSON)
EndIfthanks