1

Guys I have a big headaches trying to serialize as3 file to json with C#.

Right now i stumbled on with this =>

"licvarreelVideosConfig":[{ url: "ChoiceSlot2/GEOLJSlot/videos/00.flv", width: 224, height: 224, onWholeReel: false, transparent: true }, { url:"ChoiceSlot2/GEOLJSlot/videos/01.flv", width: 224, height: 224, onWholeReel: false, transparent: true }] 

Lets say I generate the json keys based on what is given from the as3 file.

But in some of the classes there are missing double quotes in the keys. Any easy way to properly add them ?

Thanks in advance

1 Answer 1

1
  1. If the properties are not quoted, then you can't really call this JSON.

  2. According to this site, in all the standards, except for RFC 7159, the whole content has to be wrapped in { }

  3. Putting aside these, a quick solution that comes to my mind involves using a regular expression to replace the unquoted property names with quoted ones.

Example

var unquotedJson = "\"licvarreelVideosConfig\":[{" + "url: \"ChoiceSlot2/GEOLJSlot/videos/00.flv\"," + "width: 224," + "height: 224," + "onWholeReel: false," + "transparent: true" + "}, {" + "url:\"ChoiceSlot2/GEOLJSlot/videos/01.flv\"," + "width: 224," + "height: 224," + "onWholeReel: false," + "transparent: true" + "}]"; var quotedJson = new Regex("([a-zA-Z0-9_$]+?):(.*?)[,]{0,1}").Replace(unquotedJson, "\"$1\":$2"); // if the serializer needs nested { ... } // var nestedQuotedJson = string.Format("{{{0}}}", quotedJson); // do the serialization 

Note, this is really not comprehensive, it only supports property names with a-z, A-Z, 0-9, $ and _ characters in them.

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

2 Comments

Probably the regular expression needs some thinking as well. Hope this can set you on a path to success though :)
Thanks for the answer :).RIght now everything is working fine but still I will check for exceptions. About the snipped i pasted it was just to show the idea. thanks again :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.