JsonTextParser throw FormatException when the format is good..

Last post 06-30-2009 3:15 PM by SweeT EviL. 2 replies.

Sort Posts:

  • JsonTextParser throw FormatException when the format is good..

    06-30-2009, 12:04 PM
    • Member
      43 point Member
    • SweeT EviL
    • Member since 02-13-2009, 9:12 AM
    • Posts 183

    I use this code:

    JsonTextParser pars = new JsonTextParser();
    JsonObject obj = pars.Parse(XXX);

    When the XXX equals to:
    {
    "responseData": 
    	{
    	"results":[],"cursor":
    			{
    			"moreResultsUrl":"http://www.google.com/search?oe\u003dutf8\u0026ie\u003dutf8\u0026source\u003duds\u0026start\u003d0\u0026hl\u003den\u0026q\u003d%D7%90%D7%97%D7%9C%D7%94+%D7%91%D7%97%D7%9C%D7%94+%D7%91%D7%92%D7%A8%D7%A0%D7%93+%D7%A7%D7%99%D7%99%D7%9E%D7%9F"
    			}
    	}, 
    "responseDetails": null, "responseStatus": 200
    }

    And the exception is:

        System.FormatException was unhandled by user code
          Message="Cannot parse a value."
          Source="System.Net.Json"
          StackTrace:
               at System.Net.Json.JsonTextParser.ParseSomethingWithoutName()
               at System.Net.Json.JsonTextParser.ParseCollection()
               at System.Net.Json.JsonTextParser.ParseSomethingWithoutName()
               at System.Net.Json.JsonTextParser.ParseCollection()
               at System.Net.Json.JsonTextParser.ParseSomethingWithoutName()
               at System.Net.Json.JsonTextParser.ParseCollection()
               at System.Net.Json.JsonTextParser.ParseSomethingWithoutName()
               at System.Net.Json.JsonTextParser.Parse(String text)
               at Default8.Page_Load(Object sender, EventArgs e) in c:\Documents and Settings\eViL\My Documents\Visual Studio 2008\WebSites\NewTest\Default8.aspx.cs:line 20
               at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
               at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
               at System.Web.UI.Control.OnLoad(EventArgs e)
               at System.Web.UI.Control.LoadRecursive()
               at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
          InnerException:


    I'm no expert in json but its seems like a valid json format. And I maybe think its that null, but then it would throw different exception, right?

  • Re: JsonTextParser throw FormatException when the format is good..

    06-30-2009, 2:03 PM
    • Star
      13,605 point Star
    • gt1329a
    • Member since 06-24-2002, 12:53 AM
    • Atlanta
    • Posts 2,248
    • TrustedFriends-MVPs

    If I had to guess, I would bet the empty "results" array literal is the problem.

    Encosia - ASP.NET, jQuery, AJAX, and more.

    Latest article: Emulate ASP.NET validation groups with jQuery validation
  • Re: JsonTextParser throw FormatException when the format is good..

    06-30-2009, 3:15 PM
    • Member
      43 point Member
    • SweeT EviL
    • Member since 02-13-2009, 9:12 AM
    • Posts 183

    How can I verify and solved that?

Page 1 of 1 (3 items)