Skip to content
Advertisement

Convert a series of PHP variables to a JSON object through a loop

I have an array that I loop through because the array is unknown. I would like to output the result of the loop as Json but unfortunately I always get an error message: “SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data at line 1 column 74 of the JSON data”. Here is my code.:

JavaScript

It should come out normal JSON that it looks like this.

JavaScript

Advertisement

Answer

Okay I found a solution. Here is my answer:

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