A
A
AndreyTM2014-06-11 16:26:07
PHP
AndreyTM, 2014-06-11 16:26:07

Tell me the JSON parser in PHP

Good afternoon.
There is the following string in JSON format:
{ench: [{id: 16s, lvl: 5s}]}
The built-in function json_decode() does not take it (I read that it is very picky about the format of the json string). Please tell me a json parser in php that can digest it or how to bring this string into an "edible" form for the built-in php function.

Answer the question

In order to leave comments, you need to log in

6 answer(s)
M
Misha Vasilyev, 2014-06-11
@vasilyev

Do you receive invalid json from yourself or from some external source? I mean, what can all such json fix?

A
AndreyTM, 2014-06-11
@AndreyTM

I get it from my source. The java library generates such a string. I already then take it from a DB.

M
Mykola, 2014-06-11
@iSensetivity

First, add parentheses to the elements.

O
Optimus, 2014-06-11
Pyan @marrk2

So you can write your php function for such an invalid string.

V
Vitaly Zheltyakov, 2014-06-11
@VitaZheltyakov

What is stupidity? Write your own parser - you should get a simple function with several nested loops.

E
ErickSkrauch, 2014-06-12
@ErickSkrauch

I know from experience that PHP has a good parser and you don't need to touch it. If the data source belongs to you, then it would be better to generate a valid format right away. Look for alternative json encoding libraries you use.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question