JObject.TryParse?

Feb 10, 2012 at 7:59 AM

Hi - would you consider implementing a JObject.TryParse method?

Currently I am only concerned with parsing valid json and I don't care what is wrong with it (it is processing incoming data on a webscokets server) because if it isn't valid - it'll be ignored.

I'm going to use something like this to bypass for now:

        private bool TryParseData(String data, out JObject result)
        {
            bool parseResult = false;
            JObject json = null;

            try
            {
                json = JObject.Parse(data);
                parseResult = true;
            }
            catch (Exception)
            {
                //Log it
            }

            result = json;
            return parseResult;

        }

I would be neat if the JObject provided it out of the box. It is usual (in the dotnet framework at least) to provide a TryParse wherever there is a Parse.

Thanks