Having troubles parsing JSON data

Thankfully I have a coworker here who knows a little more about json.

The most usefull trick is method chaining. I had an json array in an other array.

This stretch code solved the issue

            for (int i = 0; i < mainArray.size(); i++)
            {
                JSONObject json = mainArray.getJSONObject(i); 
                COM_PORT = json.getJSONObject("port").getString("address");
                
                if( json.getJSONArray("matching_boards") != null )
                {
                    JSONObject subObj = json.getJSONArray("matching_boards").getJSONObject(0);
                    fqbn = subObj.getString("fqbn") ;
                    break ;
                }
            }

It was slightly more difficult than I hoped :expressionless:

My entire program does now work well. I can succesfully retreive the fqbn string and corresponding com port number with which I can upload programs. In theory it should not matter, what board you plug in (as long as it is an avr due to installed cores) and which com port number your computer assigns to the arduino.

Bas

2 Likes