0

my solution was :

function format_json($str)
  {
    ...
    $str = preg_replace('/([a-z]+):/i', '"$1":', $str);
    $wtr = array('""',',",');
    $rpw = array('"',',');
    return str_replace($wtr, $rpw, $str);
  }
2
  • Keys and strings must be in double quotes. Where do you get the JSON from? Commented Jul 27, 2011 at 8:40
  • Note: This is valid JavaScript but not valid JSON. Valid JavaScript is not automatically valid JSON. Commented Jul 27, 2011 at 9:18

5 Answers 5

2

Like stated in previous answers, you need to add double-quote to strings. A really fast and quick way to check json string is to use JSONLint.

Here's the output you will get from JSONLint:

Parse error on line 1:
{    m: [        {     
-----^
Expecting 'STRING', '}'

So you need to change all parts that don't have double quotes. For example:

{m: [ ...

Will become:

{"m": [ ...

Edit after comment: It seems that the double quotes inside strings are not escaped properly. For example:

{"m" : [ { "g": [ "32", "Brezilya-"Serie" A", "83", ...
Here -----------------------------^ and ^

Should be:

{"m" : [ { "g": [ "32", "Brezilya-\"Serie\" A", "83", ...
Sign up to request clarification or add additional context in comments.

3 Comments

No worries. I hope it works out for you. Haha, just noticed what I wrote "fast and quick". It's like saying "big and large" :P
:D, all strings are now in double quotes but now the JSONLint says " invalid array length " ....
yes i see, but the probles it that the function which adds keys inside double quotes ( ex : m to " m " ) some times does things like "Brezilya-"Serie" A".. i will try to fix it
2

JSON only supports double-quoted strings, and all of the property names must be quoted.

6 Comments

just tried... don't work , the JSONLint says : " invalid array length "
Can you update your question with the data after the fixes you made?
ok i updated my question, now you can see the data after some changes
oh... the function to place keys in double quotes did some wrong things... i will try to fix it..
It looks like you surrounded a lot words with double quotes, so now some strings aren't valid. See "Brezilya-"Serie" A" for example: that isn't a valid string.
|
2

Try to run your JSON through JSONLint. To begin with, property names must be enclosed in double quotes. Then, strings must also be enclosed in double quotes instead of single quotes:

{
    "m": [
        {
            "g": [
                32,
                "Brezilya-SerieA",
                .
                .
                .

Comments

2

You can parse this string with class from here http://pear.php.net/pepr/pepr-proposal-show.php?id=198

require_once 'JSON.php';
$json = new Services_JSON();
$data = $json->decode($yourstring);

Comments

1

IN your JSON you should use " " instead of ' ' and that will get solved.

its a convention in JSON that the double qoutes will be used to define object names or objects .. try using the way u write a string in C++ for defining your json .

6 Comments

sorry, but have you read all question? I said i tried to replace single quotes '' with double quotes " " but it also don't work...
checking again for fixin it now and telling u whats wrong gimme 1 min
you need to quote the m aswell i mean it should look like {"m":[{"g" instead of {m:[{g did u tried properly qouting all the properties i think thats where its bugging ?
I will write a little function now to put all strings in quotes... thanks
No problem :) :) you should rather parse json on client side using JSON.stringify( object ) method in JavaSCRIPT or json_encode( object ) if thats PHP
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.