Click here to Skip to main content
13,597,094 members
Click here to Skip to main content

Tagged as


80 bookmarked
Posted 23 Nov 2011
Licenced CPOL

Small LINQ to JSON Library

, 6 Dec 2011
A small LinqToJSON library in C#, and how it works
using System;

namespace Ranslant.JSON.Linq
    // use only for invalid JSON text (see specs: )
    public class JsonException: Exception
        public JsonException(string s) : base("JSON: " + s)
        { }
    public class JsonParserException : Exception
        public JsonParserException(string s) : base(s)
        { }

    internal static class JExtenssions
        // extension method
        public static string ConsumeToken(this string thisString, string token, bool removeSpaceBeforeToken, bool removeSpaceAfterToken)
            string result = thisString;

            char[] spaces = { ' ', '\n', '\t', '\r' };

            if (removeSpaceBeforeToken)
                result = result.TrimStart(spaces);

            if (result.StartsWith(token))
                result = result.Remove(0, token.Length);
                throw new JsonParserException("token '" + token + "' not found");

            if (removeSpaceAfterToken)
                result = result.TrimStart(spaces);

            return result;


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Guillaume Ranslant
Software Developer IPG
Germany Germany
since 2010: C# with WPF
since 2002: C++ (MFC / QT)
since 1995: C, Java, Pascal

"if a drummer can do it, anobody can" - Bruce Dickinson

You may also be interested in...

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04-2016 | 2.8.180621.3 | Last Updated 6 Dec 2011
Article Copyright 2011 by Guillaume Ranslant
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid