开发者

Parsing JSON string containing a RegExp in .NET

I a JSON string that contains a Regular Expression: like - { "pattern": /[a-z0-9]+/i }

Is there any easy way to parse this in .NET and get resulting object/data-structure that I can use further?

I tried JSON.NET's JObject.Parse() method but it throws an exception开发者_开发问答.

Thanks in advance!


That isn't valid JSON. Regexp literals are not allowed. You could come up with some manual parsing code, but the better solution is to fix the code that outputs that to convert the regexp literal to a string.

You can use JSONLint to easily check any JSON.


If you can't fix the source (which is actually the right answer), you could try to parse it manually, but you'll have a hard time accounting for the Regex, since almost any character is valid in a regex (what if it contains : and { or })?


This json data should probably look like this:

{ "pattern": "/[a-z0-9]+/i" }

your parser is complaining, because the json your passed is not well formed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜