I am trying to parse this string into a organized set of functions:
var str = "a(b, c(e, f(h,i,j), g(k,l,m(o,p,q)) ), d(r,s,t))"
Ideally I would like to turn it into a JSON like this:
var obj = {
func:'a',
params:[
{p:'b'},
{p: {
func:'c',
params:[
{
p:'e',
p:{
func:'f',
params:[
{p:'h'},
{p:'i'},
{p:'j'}
]
},
p:'g',
params:[
{p:'k'},
{p:'l'},
{p:{
func:'m',
params:[
{p:'o'},
{p:'p'},
{p:'q'}
]
}}
]
}
]
}},
{
p:'d',
params:[
{p:'r'},
{p:'s'},
{p:'t'}
]
}
]
}
I have tried about 8 hours of mixed str.replace() str.substring(), and str.indexOf() and not had any luck.
Any help about how to go about achieving my goal would be appreocated.
note: the functions could take any number params and is not set to 3
Aucun commentaire:
Enregistrer un commentaire