Timeline for answer to Parsing Javascript (not JSON) in PHP by gnud
Current License: CC BY-SA 2.5
Post Revisions
13 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Feb 13, 2025 at 20:57 | comment | added | gre_gor |
This doesn't handle {$:"dollar",π:3.14}
|
|
| Feb 9, 2018 at 15:19 | comment | added | Osushi |
When I set {key:[{id:1,price:1000,commnet:"foo",memo:[]},{id:2,price:2000,memo:[]}]}, it occurred error. So, I developed a library to solve this issue. All test strings are passed. I hope it is useful for everyone. github.com/Osushi/jsobj2php
|
|
| Mar 8, 2017 at 13:12 | comment | added | Frank | Neat - I love it :D | |
| Sep 14, 2016 at 19:18 | comment | added | Tustin2121 |
This is nice, but it unfortunately doesn't handle multi-line objects very well. It seems to think it's done (prematurely) when it hits a }, alone on a line. And for some reason recursing too far (?) causes it to throw invalid key errors and misalign on quotes and the like? But thanks for the starting point.
|
|
| Aug 30, 2015 at 0:41 | comment | added | Jesse Chisholm |
Also, JavaScript object may start with [ if it is an array at the top level. E.g., [5,4,3,'too',"Juan"].
|
|
| Aug 28, 2013 at 8:18 | comment | added | Dr. DS | @gnud your code breaks on following javascript object {name:"Andrew", age: "11", toys: { car: [{color:"red", wheel: "1"} ,{color:"white", wheel: "4"}]}, bus: [ {av: "Mug 2013", var: [ {color:"red", wheel: "10"} ,{color:"white", wheel: "34"}], totl: 10,buy: true}]} | |
| Oct 12, 2009 at 13:47 | comment | added | gnud | This version handles quoted keys, and converts undefined to null. | |
| Oct 12, 2009 at 13:47 | history | edited | gnud | CC BY-SA 2.5 |
Moar bug fixes
|
| Oct 12, 2009 at 13:04 | comment | added | gnud | I think it will now, I've fixed some bugs for dicts in dicts and arrays in arrays. Your test string works now. | |
| Oct 12, 2009 at 13:03 | history | edited | gnud | CC BY-SA 2.5 |
Fixed some bugs, added test cases used
|
| Oct 12, 2009 at 13:00 | comment | added | Alsciende | I guess it won't work if an object is included in the value of another object and strrpos isn't right, eg '{fu:{fu:"bar"},bar:{fu:"bar"}}' | |
| Oct 12, 2009 at 12:55 | comment | added | Alsciende | It's really really nice. Two remarks : Javascript object keys can be enclosed in simple quotes or doubles quotes (usually if the key is not a valid identifier (eg contains a space)). And undefined is a valid value. | |
| Oct 12, 2009 at 12:44 | history | answered | gnud | CC BY-SA 2.5 |