public void should_add_array_elements_with_default_values() { var element = new JElement(ElementType.Array); element.AddArrayElement(ElementType.Boolean); element.AddArrayElement(ElementType.Number); element.AddArrayElement(ElementType.String); element.AddArrayElement(ElementType.Null); element.AddArrayElement(ElementType.Object); element.AddArrayElement(ElementType.Array); element.Count().ShouldEqual(6); var elements = element.ToList(); elements[0].ShouldBeAJsonBoolValueArrayElement(false); elements[1].ShouldBeAJsonNumberValueArrayElement(0); elements[2].ShouldBeAJsonStringValueArrayElement(""); elements[3].ShouldBeAJsonNullValueArrayElement(); elements[4].ShouldBeAJsonObjectArrayElement(); elements[5].ShouldBeAJsonArrayArrayElement(); }
public void should_set_array_array_element() { var element = new JElement(ElementType.Array); var array = element.AddArrayElement(ElementType.Array); array.AddArrayValueElement(1); array.AddArrayValueElement("hai"); _encoder.Encode(element).ShouldEqual("[[1,\"hai\"]]"); }
public void should_set_array_object_element() { var element = new JElement(ElementType.Array); var @object = element.AddArrayElement(ElementType.Object); @object.AddValueMember("field2", 1); @object.AddValueMember("field3", "hai"); _encoder.Encode(element).ShouldEqual("[{\"field2\":1,\"field3\":\"hai\"}]"); }
public void should_set_array_empty_object_element() { var element = new JElement(ElementType.Array); element.AddArrayElement(ElementType.Object); _encoder.Encode(element).ShouldEqual("[{}]"); }
private static void Load(JElement jsonElement, XElement xmlElement) { if (jsonElement.IsValue) jsonElement.Value = ParseJsonValue(xmlElement, jsonElement.Type); else xmlElement.Elements().ForEach(x => Load(jsonElement.Type == ElementType.Array ? jsonElement.AddArrayElement(GetElementType(x)) : jsonElement.AddMember(GetName(x), GetElementType(x)), x)); }