示例#1
0
 private static void TestWriteToJSON(CBORObject obj)
 {
     CBORObject objA = null;
       string jsonString = String.Empty;
       using (var ms = new MemoryStream()) {
     try {
       obj.WriteJSONTo(ms);
       jsonString = DataUtilities.GetUtf8String(
     ms.ToArray(),
     true);
       objA = CBORObject.FromJSONString(jsonString);
     } catch (CBORException ex) {
       throw new InvalidOperationException(jsonString, ex);
     } catch (IOException ex) {
       throw new InvalidOperationException(String.Empty, ex);
     }
       }
       CBORObject objB = CBORObject.FromJSONString(obj.ToJSONString());
       if (!objA.Equals(objB)) {
     Console.WriteLine(objA);
     Console.WriteLine(objB);
     Assert.Fail("WriteJSONTo gives different results from ToJSONString");
       }
 }