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.

2
  • 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. Commented Apr 21, 2012 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(). Commented Apr 21, 2012 at 14:18

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

You can always convert the custom format to JSON via regexes.
Which would be a real pain in the backside and probably much harder than just changing the string format where it's produced. What does the cc:ee{{aa:cd... part mean anyway?
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.

1 Comment

Sorry, I was just adding some comments on that.

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.