0

this question might have been asked already. But i really have no idea what to search for.

If I have a string like

{{aa:bb,aaa:bbb,cc:ee{{aa:cd,cdc:dd,{{ss:ee}},kk:ee}},se:ff}}

I need to get output in probably in array

ar[0] = aa:bb, ar[1]=aaa:bbb, ar[3] = {{...}}

I tried using variable.split("}}")

which is breaking the string and not getting the actual data.

Is there any recursive function to do this? I am not able to search because I have no clear idea of what objects,strings.

Krishna Deepak
  • 1,735
  • 2
  • 20
  • 31
  • 1
    You're going to have to figure out exactly how your string should be mapped to some data structure, and then you'll have to write a parser to do the conversion. – Pointy Apr 21 '12 at 14:17
  • You'll have to either do what Pointy says, or what I would recommend is that you use JSON and use the built-in `JSON.parse()`. – robbrit Apr 21 '12 at 14:18

2 Answers2

1

If you used an existing format for structuring your string, such as JSON:

["aa:bb","aaa:bbb","cc:ee",["aa:cd","cdc:dd",["ss:ee"],"kk:ee"],"se:ff"]

Then you could just run it through JSON.parse(). - It'd be far easier than trying to decode the meaning of that string without being told what it means.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
0

I think what you're looking for is how to parse a JSON string into an object. I'm not certain, but at least it looks like that based on the format of your string. Can you confirm if the source is providing JSON output?

If yes:

Read this other SO question.

Community
  • 1
  • 1
Christian
  • 1,258
  • 10
  • 11