LitJsonEncoder.cs 735 B

123456789101112131415161718192021222324252627282930
  1. #if !BESTHTTP_DISABLE_SOCKETIO
  2. using System.Collections.Generic;
  3. using LitJson;
  4. namespace BestHTTP.SocketIO.JsonEncoders
  5. {
  6. /// <summary>
  7. /// This IJsonEncoder implementation uses the LitJson library located in the Examples\LitJson directory.
  8. /// </summary>
  9. public sealed class LitJsonEncoder : IJsonEncoder
  10. {
  11. public List<object> Decode(string json)
  12. {
  13. JsonReader reader = new JsonReader(json);
  14. return JsonMapper.ToObject<List<object>>(reader);
  15. }
  16. public string Encode(List<object> obj)
  17. {
  18. JsonWriter writer = new JsonWriter();
  19. JsonMapper.ToJson(obj, writer);
  20. return writer.ToString();
  21. }
  22. }
  23. }
  24. #endif