LitJsonEncoder.cs 618 B

12345678910111213141516171819202122232425262728
  1. #if !BESTHTTP_DISABLE_SIGNALR
  2. using System.Collections.Generic;
  3. using LitJson;
  4. namespace BestHTTP.SignalR.JsonEncoders
  5. {
  6. public sealed class LitJsonEncoder : IJsonEncoder
  7. {
  8. public string Encode(object obj)
  9. {
  10. JsonWriter writer = new JsonWriter();
  11. JsonMapper.ToJson(obj, writer);
  12. return writer.ToString();
  13. }
  14. public IDictionary<string, object> DecodeMessage(string json)
  15. {
  16. JsonReader reader = new JsonReader(json);
  17. return JsonMapper.ToObject<Dictionary<string, object>>(reader);
  18. }
  19. }
  20. }
  21. #endif