public void IListGenericAdd() { IList <JToken> t = new JProperty("error", new List <string> { "one", "two" }); t.Add(1); t.Add(2); }
public void IListGenericAdd() { IList <JToken> t = new JProperty("error", new List <string> { "one", "two" }); ExceptionAssert.Throws <JsonException>(() => { t.Add(1); }, "Newtonsoft.Json.Linq.JProperty cannot have multiple values."); }
/// <summary> /// Строит представление записи в виде JSON, /// характерном для ИРБИС. /// </summary> public string ToIrbisJson() { JObject result = new JObject(); string[] tags = Fields .Select(field => field.Tag) .Distinct() .ToArray(); foreach (string tag in tags) { RecordField[] fields = Fields.GetField(tag); JProperty tagProperty = new JProperty(tag); for (int i = 0; i < fields.Length; i++) { JProperty repeatProperty = new JProperty(i.ToString()); tagProperty.Add(repeatProperty); RecordField field = fields[i]; if (!string.IsNullOrEmpty(field.Text)) { JProperty textProperty = new JProperty("*", field.Text); repeatProperty.Add(textProperty); } foreach (SubField subField in field.SubFields) { JProperty subProperty = new JProperty ( subField.CodeString, subField.Text ); repeatProperty.Add(subProperty); } } } return(result.ToString()); }
private void GenerateJSonFile(Dictionary<string, string> macros, List<string> includes, string path) { JObject root = new JObject(); JArray jarray = new JArray(); foreach (var elem in includes) { jarray.Add(elem); } JProperty global_include_paths = new JProperty("global_include_paths", jarray); JProperty projectCustomPaths = new JProperty("Project Custom Paths", new JObject(global_include_paths)); JProperty custom = new JProperty("custom", new JObject(projectCustomPaths)); foreach (var kvp in macros) { JProperty prop = new JProperty(kvp.Key, kvp.Value); custom.Add(prop); } root.Add(custom); string json = JsonConvert.SerializeObject(root, Formatting.Indented); //write string to file System.IO.File.WriteAllText($"{path}\\CxCPPDefaultMacros.json", json); }
public void IListGenericAdd() { IList<JToken> t = new JProperty("error", new List<string> { "one", "two" }); AssertException.Throws<JsonException>(() => { t.Add(1); }, "OpenGamingLibrary.Json.Linq.JProperty cannot have multiple values."); }