JSON help needed from devs (1 Viewer)

corporate_gadfly

Portal Pro
May 17, 2011
396
136
Home Country
Canada Canada
Hi devs,

I need a bit of help implementing a site. The code in my util looks like as follows:
Code:
JObject json = GetWebData<JObject>("http://ww3.tvo.org/views/ajax?view_name=video_landing_page&view_display_id=page_1");
Unfortunately, in the logs I'm getting:
[02-18 18:46:36,230] [OnlineVideos] [WARN ] System.Runtime.Serialization.SerializationException: Type 'Newtonsoft.Json.JsonReaderException' in Assembly 'OnlineVideos, Version=1.1.0.1936, Culture=neutral, PublicKeyToken=null' is not marked as serializable.

Server stack trace:
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
at System.Runtime.Remoting.Channels.CrossAppDomainSerializer.SerializeMessageParts(ArrayList argsToSerialize)
at System.Runtime.Remoting.Messaging.SmuggledMethodReturnMessage..ctor(IMethodReturnMessage mrm)
at System.Runtime.Remoting.Messaging.SmuggledMethodReturnMessage.SmuggleIfPossible(IMessage msg)
at System.Runtime.Remoting.Channels.CrossAppDomainSink.DoDispatch(Byte[] reqStmBuff, SmuggledMethodCallMessage smuggledMcm, SmuggledMethodReturnMessage& smuggledMrm)
at System.Runtime.Remoting.Channels.CrossAppDomainSink.DoTransitionDispatchCallback(Object[] args)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at OnlineVideos.Sites.SiteUtilBase.DiscoverDynamicCategories()
Can one of you try the above code and see if you can reproduce the error? Any ideas how to fix it would be welcome as well.
 

offbyone

Development Group
  • Team MediaPortal
  • April 26, 2008
    3,989
    3,712
    Stuttgart
    Home Country
    Germany Germany
    Looks like an exception is thrown and trying to pass the AppDomain, but System.Runtime.Serialization.SerializationException is not serializable. For testing you can disable the separate Appdomain (there is a boolean), I guess doskabouter did that ;) So in summary the JSON from the server seems not valid.
     

    corporate_gadfly

    Portal Pro
    May 17, 2011
    396
    136
    Home Country
    Canada Canada
    Thx to both of you. In Firebug I see the response as (cut for brevity):
    Code:
    "\n\x3cdiv id=\"view-id-video_landing_page-page_1\" class=\"view view-video-landing-page view-id-video_landing_page view-display-id-page_1 view-dom-id-1 \"\x3e
    So, I can try to search and replace:\x3c with < and \x3e with > and try to use the Parse method to parse it manually.

    Thanks again.
     

    corporate_gadfly

    Portal Pro
    May 17, 2011
    396
    136
    Home Country
    Canada Canada
    Looks like Newtonsoft.Json does not support hexadecimal escape sequences (or octal escape sequences for that matter). I would be willing to try this patch at least for the hexadecimal support (don't care about the octal part at the moment).

    Thoughts?

    Following patch works:
    Code:
    Index: OnlineVideos/Newtonsoft.Json/JsonTextReader.cs
    ===================================================================
    --- OnlineVideos/Newtonsoft.Json/JsonTextReader.cs    (revision 1935)
    +++ OnlineVideos/Newtonsoft.Json/JsonTextReader.cs    (working copy)
    @@ -132,6 +132,19 @@
                      char hexChar = Convert.ToChar(int.Parse(new string(hexValues), NumberStyles.HexNumber, NumberFormatInfo.InvariantInfo));
                      _buffer.Append(hexChar);
                      break;
    +                case 'x':
    +                  hexValues = new char[2];
    +                  for (int i = 0; i < hexValues.Length; i++)
    +                  {
    +                      if ((currentChar = MoveNext()) != '\0' || !_end)
    +                          hexValues[i] = currentChar;
    +                      else
    +                          throw CreateJsonReaderException("Unexpected end while parsing hexadecimal escape sequence. Line {0}, position {1}.", _currentLineNumber, _currentLinePosition);
    +                  }
    +
    +                  hexChar = Convert.ToChar(int.Parse(new string(hexValues), NumberStyles.HexNumber, NumberFormatInfo.InvariantInfo));
    +                  _buffer.Append(hexChar);
    +                  break;
                    default:
                      throw CreateJsonReaderException("Bad JSON escape sequence: {0}. Line {1}, position {2}.", @"\" + currentChar, _currentLineNumber, _currentLinePosition);
                  }
    Any protocol for updating Newtonsoft.JSON that I should follow?
     

    offbyone

    Development Group
  • Team MediaPortal
  • April 26, 2008
    3,989
    3,712
    Stuttgart
    Home Country
    Germany Germany
    Just go with it :) That's the reason I included the source not the dll. Maybe there is a newer release of those sources I should use? Don't know from when the source I used were.
     

    Users who are viewing this thread

    Top Bottom