Skip to content
Advertisement

Parse multidimensional arrays in GO

I wold like to parse a multidimensional array in GO

The goal is to unserialize a array string a run into a loop to get the values.

In PHP, i use this:

Code:

JavaScript

Output:

JavaScript

In GO, i manage to unserialize the string but i don’t know how to run the loop like in php

Code:

JavaScript

Output:

JavaScript

Anyone can help?

Advertisement

Answer

In Golang you haven’t any parser for unknown arrays or objects, your unknown data is the interface so first, you should cast the data to an array or object and then loop through it, the below code will do what you want.

JavaScript

output:

JavaScript

also, this package hasn’t any casting method like json.Unmarshal so you should do it with your own knowledge of your data.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement