protected WriteEnd ( JsonToken token ) : void | ||
token | JsonToken | The end token to write. |
리턴 | void |
public void ProcessRequest(HttpContext context) { string reVal = string.Empty; context.Response.ContentType = "text/plain"; IEnumerable<ADM_USER> list = from m in etMgr.ADM_USER.OfType<ADM_USER>() select m; StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); using (JsonWriter jsonWriter = new JsonTextWriter(sw)) { jsonWriter.Formatting = Formatting.Indented; jsonWriter.WriteStartArray(); foreach (ADM_USER m in list) { jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("name"); jsonWriter.WriteValue(string.IsNullOrEmpty(m.REAL_NAME) ? m.USERNAME : m.REAL_NAME); jsonWriter.WritePropertyName("id"); jsonWriter.WriteValue(m.USER_ID); jsonWriter.WriteEndObject(); } jsonWriter.WriteEnd(); } reVal = sb.ToString(); context.Response.Write(reVal); }
static void Main(string[] args) { StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); using (JsonWriter writer = new JsonTextWriter(sw)) { writer.Formatting = Newtonsoft.Json.Formatting.Indented; writer.WriteStartObject(); writer.WritePropertyName("CPU"); writer.WriteValue("Intel"); writer.WritePropertyName("PSU"); writer.WriteValue("500W"); writer.WritePropertyName("Drives"); writer.WriteStartArray(); writer.WriteValue("DVD read/writer"); writer.WriteComment("(broken)"); writer.WriteValue("500 gigabyte hard drive"); writer.WriteValue("200 gigabype hard drive"); writer.WriteEnd(); writer.WriteEndObject(); } File.WriteAllText(Environment.CurrentDirectory + "/rhcdata.json", sw.ToString()); Console.WriteLine(sw.ToString()); Console.ReadLine(); }
private void WriteChildren(Dictionary<string, TreeElement> children, JsonTextWriter writer) { writer.WriteStartObject(); foreach (var child in children) { writer.WritePropertyName(child.Key); WriteFrame(child.Value, writer); } writer.WriteEnd(); }
public bool Start(string context) { this.context = context; string uri = baseURI + @"start/"; string method = "POST"; StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); using (JsonWriter jsonWriter = new JsonTextWriter(sw)) { jsonWriter.Formatting = Formatting.Indented; jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("context"); jsonWriter.WriteValue(this.context); jsonWriter.WritePropertyName("participants"); jsonWriter.WriteStartArray(); jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("name"); // use the current window user jsonWriter.WriteValue(Environment.UserName); jsonWriter.WritePropertyName("id"); // use the computer name + windows user name jsonWriter.WriteValue(Environment.MachineName + "-" + Environment.UserName); jsonWriter.WriteEndObject(); jsonWriter.WriteEnd(); jsonWriter.WriteEndObject(); } string json = sb.ToString(); HttpWebRequest req = WebRequest.Create(uri) as HttpWebRequest; req.KeepAlive = false; req.Method = method; byte[] buffer = Encoding.ASCII.GetBytes(json); req.ContentLength = buffer.Length; req.ContentType = "application/json"; Stream PostData = req.GetRequestStream(); PostData.Write(buffer, 0, buffer.Length); PostData.Close(); HttpWebResponse resp = req.GetResponse() as HttpWebResponse; StreamReader tr = new StreamReader(resp.GetResponseStream()); json = tr.ReadToEnd(); Dictionary<string, string> respValues = JsonConvert.DeserializeObject<Dictionary<string, string>>(json); if (respValues.ContainsKey("status") && respValues["status"] == "success") { this.dialogueID = respValues["dlg_id"]; this.IsRunning = true; return true; } return false; }
protected void Page_Load(object sender, EventArgs e) { Response.Clear(); var oSB = new StringBuilder(); var oSW = new StringWriter(oSB); using (JsonWriter oWriter = new JsonTextWriter(oSW)) { oWriter.Formatting = Formatting.Indented; oWriter.WriteStartObject(); if (IsAuthenticated && ApplicationContext.IsStaff) { oWriter.WritePropertyName("results"); oWriter.WriteStartArray(); if (!string.IsNullOrEmpty(Request.QueryString["q"])) { var sQuery = Request.QueryString["q"]; DataAccess.Log = new DebugTextWriter(); var oResults = DataAccess.fn_Producer_GetCustomerLookup(); oResults = oResults.Where(row => (row.FirstName + " " + row.LastName + " (" + row.Username + ")").Contains(sQuery)) .Distinct().Take(30); foreach (var oResult in oResults) { oWriter.WriteStartObject(); oWriter.WritePropertyName("id"); oWriter.WriteValue(oResult.MPUserID.ToString()); oWriter.WritePropertyName("name"); oWriter.WriteValue(string.Format("{0} {1} ({2})", oResult.FirstName, oResult.LastName, oResult.Username)); oWriter.WriteEndObject(); } oWriter.WriteEnd(); } } oWriter.WriteEndObject(); } Response.ContentType = "application/json"; Response.Write(oSB.ToString()); Response.End(); }
public void ProcessRequest(HttpContext context) { string reVal = string.Empty; try { context.Response.ContentType = "text/plain"; IEnumerable<MENU> list = from m in etMgr.MENU.OfType<MENU>() where m.PARENT_ID == 0 select m; StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); using (JsonWriter jsonWriter = new JsonTextWriter(sw)) { jsonWriter.Formatting = Formatting.Indented; jsonWriter.WriteStartArray(); foreach (MENU m in list) { jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("name"); jsonWriter.WriteValue(m.NAME); jsonWriter.WritePropertyName("id"); jsonWriter.WriteValue(m.MENU_ID); jsonWriter.WritePropertyName("url"); jsonWriter.WriteValue(m.URL); jsonWriter.WritePropertyName("target"); jsonWriter.WriteValue(string.IsNullOrEmpty(m.TARGET.Trim()) ? "_parent" : m.TARGET); if (etMgr.MENU.Count(me => me.PARENT_ID == m.MENU_ID) > 0) { jsonWriter.WritePropertyName("nodes"); sb.Append(GetChildStr(m.MENU_ID)); } jsonWriter.WriteEndObject(); } jsonWriter.WriteEnd(); } reVal = sb.ToString(); } catch (Exception ex) { Com.Mxm.WriteTxt.WriteText(ex.Message); } finally { etMgr.Dispose(); } context.Response.Write(reVal); }
internal JObject MapPropertiesFromAttributes() { int seen; if (this.SeenTypes.TryGetValue(this._type, out seen) && seen > MaxRecursion) return JObject.Parse("{}"); var sb = new StringBuilder(); using (StringWriter sw = new StringWriter(sb)) using (JsonWriter jsonWriter = new JsonTextWriter(sw)) { jsonWriter.WriteStartObject(); { this.WriteProperties(jsonWriter); } jsonWriter.WriteEnd(); return JObject.Parse(sw.ToString()); } }
public AuthRequest(string _user, string _password, string _sku) { user = _user; password = _password; sku = _sku; StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); JsonWriter jsonWriter = new JsonTextWriter(sw); jsonWriter.Formatting = Formatting.None; jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("priorityLevel"); jsonWriter.WriteValue(6); jsonWriter.WritePropertyName("sku"); jsonWriter.WriteValue(sku); jsonWriter.WritePropertyName("clientVersion"); jsonWriter.WriteValue(3); jsonWriter.WritePropertyName("method"); jsonWriter.WriteValue("nucemail"); jsonWriter.WritePropertyName("macAddress"); jsonWriter.WriteValue("38:2c:4a:6e:14:05"); jsonWriter.WritePropertyName("locale"); jsonWriter.WriteValue("en-US"); jsonWriter.WritePropertyName("identification"); jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("user"); jsonWriter.WriteValue(user); jsonWriter.WritePropertyName("password"); jsonWriter.WriteValue(password); jsonWriter.WriteEndObject(); jsonWriter.WriteEnd(); Body = sb.ToString(); }
private StringWriter WriteDataProviderScheme(ISet<IDataProviderScheme> dataproviderscheme, string resourceId, StringWriter sw) { if (dataproviderscheme.Count > 0) { foreach (IDataProviderScheme dataprovider in dataproviderscheme) { using (JsonWriter writer = new JsonTextWriter(sw)) { // writer.Formatting = Newtonsoft.Json.Formatting.Indented; bool isIndented = Convert.ToBoolean(ConfigurationManager.AppSettings["isIndented"]); if (isIndented == true) { writer.Formatting = Newtonsoft.Json.Formatting.Indented; } writer.WriteStartObject(); writer.WritePropertyName("DPS"); writer.WriteStartArray(); writer.WriteStartObject(); writer.WritePropertyName("id"); writer.WriteValue("DATA_PROVIDERS"); writer.WritePropertyName("agencyID"); writer.WriteValue(dataprovider.AgencyId); writer.WritePropertyName("version"); writer.WriteValue(dataprovider.Version); writer.WritePropertyName("stub"); writer.WriteValue("false"); writer.WritePropertyName("isFinal"); writer.WriteValue(dataprovider.IsFinal.IsTrue); writer.WritePropertyName("externalReference"); writer.WriteValue(dataprovider.IsExternalReference.IsTrue); writer.WritePropertyName("names"); writer.WriteStartObject(); foreach (var item in dataprovider.Names) { writer.WritePropertyName(item.Locale); writer.WriteValue(item.Value); } writer.WriteEndObject(); writer.WritePropertyName("descriptions"); writer.WriteStartObject(); foreach (var item in dataprovider.Descriptions) { writer.WritePropertyName(item.Locale); writer.WriteValue(item.Value); } writer.WriteEndObject(); writer.WritePropertyName("dataProviders"); writer.WriteStartObject(); //////////////////////// foreach (var item in dataprovider.Items) { writer.WritePropertyName(item.Id); writer.WriteStartObject(); writer.WritePropertyName("id"); writer.WriteValue(item.Id); writer.WritePropertyName("names"); foreach (var item1 in item.Names) { writer.WriteStartObject(); writer.WritePropertyName(item1.Locale); writer.WriteValue(item1.Value); writer.WriteEndObject(); } writer.WriteEndObject(); } //////////////////////// writer.WriteEnd(); writer.WritePropertyName("accessLevel"); writer.WriteValue("PUBLIC"); //writer.WritePropertyName("lastUpdateDate"); //writer.WriteValue(codelistBean.IsExternalReference); writer.WritePropertyName("type"); writer.WriteValue("DPS"); writer.WritePropertyName("canBeMaintained"); writer.WriteValue("true"); writer.WriteEndObject(); writer.WriteEndArray(); writer.WriteEndObject(); } } } return sw; }
/// <summary>写入文档结束标记。</summary> public void WriteEndDocument() { //_textWriter.WriteEndObject(); _textWriter.WriteEnd(); }
public void WriteRawInObject() { StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); using (JsonWriter jsonWriter = new JsonTextWriter(sw)) { jsonWriter.Formatting = Formatting.Indented; jsonWriter.WriteStartObject(); jsonWriter.WriteRaw(@"""PropertyName"":[1,2,3,4,5]"); jsonWriter.WriteEnd(); } string expected = @"{""PropertyName"":[1,2,3,4,5]}"; string result = sb.ToString(); Assert.AreEqual(expected, result); }
public void Indenting() { StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); using (JsonWriter jsonWriter = new JsonTextWriter(sw)) { jsonWriter.Formatting = Formatting.Indented; jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("CPU"); jsonWriter.WriteValue("Intel"); jsonWriter.WritePropertyName("PSU"); jsonWriter.WriteValue("500W"); jsonWriter.WritePropertyName("Drives"); jsonWriter.WriteStartArray(); jsonWriter.WriteValue("DVD read/writer"); jsonWriter.WriteComment("(broken)"); jsonWriter.WriteValue("500 gigabyte hard drive"); jsonWriter.WriteValue("200 gigabype hard drive"); jsonWriter.WriteEnd(); jsonWriter.WriteEndObject(); Assert.AreEqual(WriteState.Start, jsonWriter.WriteState); } // { // "CPU": "Intel", // "PSU": "500W", // "Drives": [ // "DVD read/writer" // /*(broken)*/, // "500 gigabyte hard drive", // "200 gigabype hard drive" // ] // } string expected = @"{ ""CPU"": ""Intel"", ""PSU"": ""500W"", ""Drives"": [ ""DVD read/writer"" /*(broken)*/, ""500 gigabyte hard drive"", ""200 gigabype hard drive"" ] }"; string result = sb.ToString(); Assert.AreEqual(expected, result); }
public void QuoteChar() { StringWriter sw = new StringWriter(); JsonTextWriter writer = new JsonTextWriter(sw); writer.Formatting = Formatting.Indented; writer.QuoteChar = '\''; writer.WriteStartArray(); writer.WriteValue(new DateTime(2000, 1, 1, 1, 1, 1, DateTimeKind.Utc)); writer.WriteValue(new DateTimeOffset(2000, 1, 1, 1, 1, 1, TimeSpan.Zero)); writer.DateFormatHandling = DateFormatHandling.MicrosoftDateFormat; writer.WriteValue(new DateTime(2000, 1, 1, 1, 1, 1, DateTimeKind.Utc)); writer.WriteValue(new DateTimeOffset(2000, 1, 1, 1, 1, 1, TimeSpan.Zero)); writer.DateFormatString = "yyyy gg"; writer.WriteValue(new DateTime(2000, 1, 1, 1, 1, 1, DateTimeKind.Utc)); writer.WriteValue(new DateTimeOffset(2000, 1, 1, 1, 1, 1, TimeSpan.Zero)); writer.WriteValue(new byte[] { 1, 2, 3 }); writer.WriteValue(TimeSpan.Zero); writer.WriteValue(new Uri("http://www.google.com/")); writer.WriteValue(Guid.Empty); writer.WriteEnd(); Assert.AreEqual(@"[ '2000-01-01T01:01:01Z', '2000-01-01T01:01:01+00:00', '\/Date(946688461000)\/', '\/Date(946688461000+0000)\/', '2000 A.D.', '2000 A.D.', 'AQID', '00:00:00', 'http://www.google.com/', '00000000-0000-0000-0000-000000000000' ]", sw.ToString()); }
//把返回值编译成json格式 public string uploadFileResult(string result) { StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); using (JsonWriter jswriter = new JsonTextWriter(sw)) { jswriter.Formatting = Formatting.Indented; jswriter.WriteStartObject(); jswriter.WritePropertyName("result"); jswriter.WriteValue(result); jswriter.WriteEnd(); } return sb.ToString(); }
private string ModsToJson(List<Mod> mods) { StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); using (JsonWriter writer = new JsonTextWriter(sw)) { writer.Formatting = Formatting.Indented; writer.WriteComment("DO NOT EDIT THIS BY HAND WITHOUT KNOWING EXACTLY WHAT YOU ARE DOING" + Environment.NewLine + "THIS FILE IS CREATED BY MCM AND IS USED FOR KNOWING WHICH MODS ARE INSTALLED!"); writer.WriteStartObject(); writer.WritePropertyName("mods"); writer.WriteStartArray(); foreach (Mod mod in mods) { writer.WriteStartObject(); writer.WritePropertyName("name"); writer.WriteValue(mod.name); writer.WritePropertyName("path"); writer.WriteValue(mod.path); writer.WritePropertyName("type"); writer.WriteValue(mod.type); writer.WritePropertyName("level"); writer.WriteValue(mod.level); writer.WritePropertyName("version"); writer.WriteValue(mod.version.Key); writer.WriteEndObject(); } writer.WriteEnd(); } return sb.ToString(); }
private string GetChildStr(int parent_id) { string reVal = string.Empty; if (parent_id > 0) { IList<MENU> list; using (etMgr = new MYCRMEntities()) { var lst = from m in etMgr.MENU.OfType<MENU>() where m.PARENT_ID == parent_id && m.STATUS==1 select m; list = lst.ToList<MENU>(); } StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); using (JsonWriter jsonWriter = new JsonTextWriter(sw)) { jsonWriter.Formatting = Formatting.Indented; jsonWriter.WriteStartArray(); foreach (MENU m in list) { jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("name"); jsonWriter.WriteValue(m.NAME); jsonWriter.WritePropertyName("id"); jsonWriter.WriteValue(m.MENU_ID); jsonWriter.WritePropertyName("url"); jsonWriter.WriteValue(m.URL); jsonWriter.WritePropertyName("target"); jsonWriter.WriteValue(string.IsNullOrEmpty(m.TARGET.Trim()) ? "_parent" : m.TARGET); int count = 0; using (etMgr = new MYCRMEntities()) { count = etMgr.MENU.Count(me => me.PARENT_ID == m.MENU_ID && me.STATUS==1); } if (count > 0) { jsonWriter.WritePropertyName("nodes"); sb.Append(GetChildStr(m.MENU_ID)); } jsonWriter.WriteEndObject(); } jsonWriter.WriteEnd(); } reVal = sb.ToString(); } return reVal; }
public void SaveAnim(string name) { if (!Directory.Exists("blueprints\\anim")) { Directory.CreateDirectory("blueprints\\anim"); } FileStream fs = File.Open("blueprints\\anim\\" + name + ".json", FileMode.Create); StreamWriter sw = new StreamWriter(fs); JsonTextWriter jw = new JsonTextWriter(sw); jw.Formatting = Formatting.Indented; jw.WriteStartObject(); //anim jw.WritePropertyName("animations"); jw.WriteStartArray(); foreach (Animation a in anims) { jw.WriteStartObject(); jw.WritePropertyName("name"); jw.WriteValue(a.name); jw.WritePropertyName("speed"); jw.WriteValue(a.speed); jw.WritePropertyName("loop"); jw.WriteValue(a.loopback); jw.WritePropertyName("frames"); jw.WriteValue(a.frames.Count); //collision jw.WritePropertyName("collisionVolumes"); jw.WriteStartArray(); for (int i = 0; i < a.frames.Count; i++) { if (a.collision[i].Count > 0) { jw.WriteStartObject(); jw.WritePropertyName("volumes"); jw.WriteStartArray(); foreach (CollisionList cl in a.collision[i]) { jw.WriteStartObject(); jw.WritePropertyName("physical"); jw.WriteValue(cl.Physical); jw.WritePropertyName("centerX"); jw.WriteValue(a.frames[i].Width / 2); jw.WritePropertyName("centerY"); jw.WriteValue(a.frames[i].Height / 2); jw.WritePropertyName("xpoints"); jw.WriteStartArray(); foreach (CollisionPoint p in cl.Nodes) { jw.WriteValue(p.X - (a.frames[i].Width / 2)); } jw.WriteEnd(); jw.WritePropertyName("ypoints"); jw.WriteStartArray(); foreach (CollisionPoint p in cl.Nodes) { jw.WriteValue(p.Y - (a.frames[i].Height / 2)); } jw.WriteEnd(); jw.WriteEnd(); } jw.WriteEnd(); jw.WriteEnd(); } else { jw.WriteWhitespace(""); } } jw.WriteEnd(); // end anim jw.WriteEnd(); } jw.WriteEnd(); jw.WriteEnd(); jw.Close(); if (!Directory.Exists("images\\anim")) { Directory.CreateDirectory("images\\anim"); } if (!Directory.Exists("images\\anim\\" + name)) { Directory.CreateDirectory("images\\anim\\" + name); } foreach (Animation a in anims) { if (!Directory.Exists("images\\anim\\" + name + "\\" + a.name)) { Directory.CreateDirectory("images\\anim\\" + name + "\\" + a.name); } int frameNum = 0; foreach (Texture2D t in a.frames) { Stream s = File.OpenWrite("images\\anim\\" + name + "\\" + a.name + "\\" + frameNum + ".png"); t.SaveAsPng(s, t.Width, t.Height); s.Close(); frameNum++; } } }
public static void Save() { string levelName = "testlevel"; FileStream fs = File.Open(levelName + ".json", FileMode.Create); StreamWriter sw = new StreamWriter(fs); JsonTextWriter jw = new JsonTextWriter(sw); jw.Formatting = Formatting.Indented; jw.WriteStartObject(); jw.WritePropertyName("entities"); jw.WriteStartArray(); foreach (Layer layer in layers) { foreach (Entity e in layer.Entities) { e.SaveEntity(ref jw); } } jw.WriteEnd(); jw.WriteEnd(); jw.Close(); }
private string CreateJsonObject(IEnumerable<IMeasurement> measurements) { StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); JsonWriter writer = new JsonTextWriter(sw); using (writer) { writer.Formatting = Formatting.Indented; writer.WriteStartObject(); foreach (IGrouping<string, IMeasurement> measurementByType in measurements.GroupBy(measurement => measurement.Type)) { writer.WritePropertyName(measurementByType.Key + "s"); writer.WriteStartArray(); foreach (IMeasurement measurement in measurements.Where(m => m.Type == measurementByType.Key)) { this.JsonWriteMeasurement(writer, measurement); } writer.WriteEnd(); } writer.WriteEndObject(); } return sb.ToString(); }
internal string MapFromAttributes() { var sb = new StringBuilder(); using (var sw = new StringWriter(sb)) using (var jsonWriter = new JsonTextWriter(sw)) { jsonWriter.Formatting = Formatting.Indented; jsonWriter.WriteStartObject(); { var typeName = this.Infer.TypeName(this.TypeName); jsonWriter.WritePropertyName(typeName); jsonWriter.WriteStartObject(); { jsonWriter.WritePropertyName("properties"); jsonWriter.WriteStartObject(); { this.WriteProperties(jsonWriter); } jsonWriter.WriteEnd(); } jsonWriter.WriteEnd(); } jsonWriter.WriteEndObject(); return sw.ToString(); } }
private StringWriter WriteCodelist(ISet<ICodelistObject> codelists, string resourceId, StringWriter sw) { if (codelists.Count > 0) { using (JsonWriter writer = new JsonTextWriter(sw)) { //writer.Formatting = Newtonsoft.Json.Formatting.Indented; bool isIndented = Convert.ToBoolean(ConfigurationManager.AppSettings["isIndented"]); if (isIndented == true) { writer.Formatting = Newtonsoft.Json.Formatting.Indented; } writer.WriteStartObject(); foreach (ICodelistObject codelistBean in codelists) { writer.WritePropertyName("CDL"); writer.WriteStartArray(); writer.WriteStartObject(); writer.WritePropertyName("id"); writer.WriteValue(codelistBean.Id); writer.WritePropertyName("agencyID"); writer.WriteValue(codelistBean.AgencyId); writer.WritePropertyName("version"); writer.WriteValue(codelistBean.Version); if (codelistBean.StartDate!= null) { writer.WritePropertyName("startDate"); writer.WriteValue(codelistBean.StartDate); } if (codelistBean.EndDate != null) { writer.WritePropertyName("endDate"); writer.WriteValue(codelistBean.EndDate); } writer.WritePropertyName("isFinal"); writer.WriteValue(codelistBean.IsFinal.IsTrue); writer.WritePropertyName("externalReference"); writer.WriteValue(codelistBean.IsExternalReference.IsTrue); writer.WritePropertyName("names"); writer.WriteStartObject(); foreach (var item in codelistBean.Names) { writer.WritePropertyName(item.Locale); writer.WriteValue(item.Value); } writer.WriteEndObject(); writer.WritePropertyName("codes"); writer.WriteStartObject(); //////////////////////// IList<ICode> codes = codelistBean.Items; if (codes.Count > 0) { foreach (ICode codeBean in codes) { writer.WritePropertyName(codeBean.Id); writer.WriteStartObject(); writer.WritePropertyName("id"); writer.WriteValue(codeBean.Id); writer.WritePropertyName("names"); writer.WriteStartObject(); foreach (var codeName in codeBean.Names) { writer.WritePropertyName(codeName.Locale); writer.WriteValue(codeBean.Id); } writer.WriteEndObject(); // writer.WriteComment("(broken)"); writer.WritePropertyName("descriptions"); writer.WriteStartObject(); foreach (var codeDesc in codeBean.Names) { writer.WritePropertyName(codeDesc.Locale); writer.WriteValue(codeDesc.Value); } writer.WriteEndObject(); writer.WriteEndObject(); } } writer.WriteEnd(); writer.WritePropertyName("accessLevel"); writer.WriteValue("PUBLIC"); //writer.WritePropertyName("lastUpdateDate"); //writer.WriteValue(codelistBean.IsExternalReference); writer.WritePropertyName("type"); writer.WriteValue("CDL"); writer.WritePropertyName("canBeMaintained"); writer.WriteValue("true"); writer.WriteEndObject(); writer.WriteEndArray(); } writer.WriteEndObject(); } } return sw; }
public StringValue GetWorkSequence(string sWorkerId) { DisableCache(); Logger.Info(string.Format("GetWorkSequence: {0}", sWorkerId)); StringBuilder sb = new StringBuilder(); try { using (Feng.IRepository rep = new Feng.NH.Repository("zkzx.model.config")) { var clzy = rep.Get<Zkzx.Model.车辆作业>(Guid.Parse(sWorkerId)); if (clzy != null) { int[] taskIdx = null; string[] importantAreas = null; string[] importantTaskStatus = null; string[] importantWorkStatus = null; string workTitle = ModelHelper.Get任务状态(clzy.专家任务, out taskIdx, out importantAreas, out importantTaskStatus, out importantWorkStatus); //clzy.最新作业状态.任务进程 StringWriter sw = new StringWriter(sb); using (JsonWriter writer = new JsonTextWriter(sw)) { writer.Formatting = Formatting.Indented; writer.WriteStartObject(); writer.WritePropertyName("Title"); writer.WriteValue(workTitle); writer.WritePropertyName("Actions"); writer.WriteStartArray(); foreach (string s in importantWorkStatus) { writer.WriteValue(s); } writer.WriteEnd(); writer.WritePropertyName("TaskIdxs"); writer.WriteStartArray(); foreach (int s in taskIdx) { writer.WriteValue(s); } writer.WriteEnd(); writer.WritePropertyName("ActionIdx"); if (!clzy.开始时间.HasValue || clzy.结束时间.HasValue) writer.WriteValue(-1); else writer.WriteValue(clzy.最新作业状态.作业进程序号); writer.WritePropertyName("ActionIdxIdx"); if (!string.IsNullOrEmpty(clzy.最新作业状态.作业状态)) { if (clzy.最新作业状态.作业状态.EndsWith("途中")) writer.WriteValue(1); else if (clzy.最新作业状态.作业状态.EndsWith("中")) writer.WriteValue(0); else writer.WriteValue(-1); } else { writer.WriteValue(1); } writer.WritePropertyName("Xianghao"); writer.WriteStartArray(); foreach (var rw in clzy.专家任务.任务) { writer.WriteValue(string.IsNullOrEmpty(rw.箱号) ? string.Empty : rw.箱号); } writer.WriteEnd(); writer.WritePropertyName("Fengzihao"); writer.WriteStartArray(); foreach (var rw in clzy.专家任务.任务) { writer.WriteValue(string.IsNullOrEmpty(rw.封志号) ? string.Empty : rw.封志号); } writer.WriteEnd(); writer.WriteEndObject(); } } } } catch (Exception ex) { ExceptionProcess.ProcessWithResume(ex); } return new StringValue { Value = sb.ToString() }; }
private StringWriter WriteDataflow(ISet<IDataflowObject> dataflow, string resourceId, StringWriter sw) { if (dataflow.Count > 0) { using (JsonWriter writer = new JsonTextWriter(sw)) { //writer.Formatting = Newtonsoft.Json.Formatting.Indented; bool isIndented = Convert.ToBoolean(ConfigurationManager.AppSettings["isIndented"]); if (isIndented == true) { writer.Formatting = Newtonsoft.Json.Formatting.Indented; } writer.WriteStartObject(); foreach (IDataflowObject dataflowBean in dataflow) { writer.WritePropertyName("DFD"); writer.WriteStartArray(); writer.WriteStartObject(); writer.WritePropertyName("id"); writer.WriteValue(dataflowBean.Id); writer.WritePropertyName("agencyID"); writer.WriteValue(dataflowBean.AgencyId); writer.WritePropertyName("version"); writer.WriteValue(dataflowBean.Version); if (dataflowBean.StartDate != null) { writer.WritePropertyName("startDate"); writer.WriteValue(dataflowBean.StartDate); } if (dataflowBean.EndDate != null) { writer.WritePropertyName("endDate"); writer.WriteValue(dataflowBean.EndDate); } writer.WritePropertyName("isFinal"); writer.WriteValue(dataflowBean.IsFinal.IsTrue); writer.WritePropertyName("externalReference"); writer.WriteValue(dataflowBean.IsExternalReference.IsTrue); writer.WritePropertyName("names"); writer.WriteStartObject(); foreach (var item in dataflowBean.Names) { writer.WritePropertyName(item.Locale); writer.WriteValue(item.Value); } writer.WriteEndObject(); writer.WritePropertyName("structure"); writer.WriteStartObject(); //////////////////////// writer.WritePropertyName("id"); writer.WriteValue(dataflowBean.DataStructureRef.MaintainableId); writer.WritePropertyName("agencyID"); writer.WriteValue(dataflowBean.AgencyId); writer.WritePropertyName("version"); writer.WriteValue(dataflowBean.Version); writer.WritePropertyName("refclass"); writer.WriteValue("Data Structure Definition"); writer.WritePropertyName("urn"); writer.WriteValue(dataflowBean.Urn); //////////////////////// writer.WriteEnd(); writer.WritePropertyName("accessLevel"); writer.WriteValue("PUBLIC"); //writer.WritePropertyName("lastUpdateDate"); //writer.WriteValue(codelistBean.IsExternalReference); writer.WritePropertyName("type"); writer.WriteValue("DFD"); writer.WritePropertyName("canBeMaintained"); writer.WriteValue("true"); writer.WriteEndObject(); writer.WriteEndArray(); } writer.WriteEndObject(); } } return sw; }
public void WriteEndOnProperty() { StringWriter sw = new StringWriter(); JsonTextWriter writer = new JsonTextWriter(sw); writer.QuoteChar = '\''; writer.WriteStartObject(); writer.WritePropertyName("Blah"); writer.WriteEnd(); Assert.AreEqual("{'Blah':null}", sw.ToString()); }
private StringWriter WriteDatastructure(ISet<IDataStructureObject> datastructure, string resourceId, StringWriter sw) { string tre = ""; if (datastructure.Count > 0) { using (JsonWriter writer = new JsonTextWriter(sw)) { //writer.Formatting = Newtonsoft.Json.Formatting.Indented; bool isIndented = Convert.ToBoolean(ConfigurationManager.AppSettings["isIndented"]); if (isIndented == true) { writer.Formatting = Newtonsoft.Json.Formatting.Indented; } writer.WriteStartObject(); foreach (IDataStructureObject datastructureBean in datastructure) { writer.WritePropertyName("DSD"); if (datastructureBean.Id.Contains("SEP_POP_NUZ") == true) tre = "ASIA"; writer.WriteStartArray(); writer.WriteStartObject(); writer.WritePropertyName("id"); writer.WriteValue(datastructureBean.Id); writer.WritePropertyName("agencyID"); writer.WriteValue(datastructureBean.AgencyId); writer.WritePropertyName("version"); writer.WriteValue(datastructureBean.Version); if (datastructureBean.StartDate != null) { if (datastructureBean.StartDate.DateInSdmxFormat != null) { writer.WritePropertyName("startDate"); writer.WriteValue(datastructureBean.StartDate.DateInSdmxFormat); } } if (datastructureBean.EndDate != null) { if (datastructureBean.EndDate.DateInSdmxFormat != null) { writer.WritePropertyName("endDate"); writer.WriteValue(datastructureBean.EndDate.DateInSdmxFormat); } } writer.WritePropertyName("isFinal"); writer.WriteValue(datastructureBean.IsFinal.IsTrue); writer.WritePropertyName("externalReference"); writer.WriteValue(datastructureBean.IsExternalReference.IsTrue); writer.WritePropertyName("names"); writer.WriteStartObject(); foreach (var item in datastructureBean.Names) { writer.WritePropertyName(item.Locale); writer.WriteValue(item.Value); } writer.WriteEndObject(); writer.WritePropertyName("dimensions"); writer.WriteStartObject(); foreach (IDimension dimensions in datastructureBean.DimensionList.Dimensions) { //////////////////////// //writer.WritePropertyName("FREQ"); writer.WritePropertyName(dimensions.Id); writer.WriteStartObject(); writer.WritePropertyName("id"); writer.WriteValue(dimensions.Id); writer.WritePropertyName("refclass"); writer.WriteValue("Dimension"); writer.WritePropertyName("position"); writer.WriteValue(dimensions.Position); writer.WritePropertyName("conceptScheme"); writer.WriteStartObject(); writer.WritePropertyName("id"); // // ??????????????????????????????????? writer.WriteValue(dimensions.ConceptRef.MaintainableId); writer.WritePropertyName("agencyID"); writer.WriteValue(dimensions.ConceptRef.AgencyId); //writer.WriteValue("ESTAT"); writer.WritePropertyName("version"); writer.WriteValue(dimensions.ConceptRef.Version); writer.WritePropertyName("refclass"); writer.WriteValue("Concept"); writer.WritePropertyName("conceptID"); writer.WriteValue(dimensions.ConceptRef.FullId); //writer.WriteValue("FREQ"); writer.WriteEndObject(); //var erx = dimensi; if(dimensions.Representation != null) { if (dimensions.Representation.CrossReferences != null) { ISet<ICrossReference> isr = dimensions.Representation.CrossReferences; foreach (var x in isr) { //var codelist = x.MaintainableReference.MaintainableId; //var agenzia = x.MaintainableReference.AgencyId; //var versione = x.MaintainableReference.Version; //var urn = x.TargetUrn.AbsoluteUri; writer.WritePropertyName("localRepresentation"); writer.WriteStartObject(); writer.WritePropertyName("urn"); writer.WriteValue(x.TargetUrn.AbsoluteUri); //writer.WriteValue("urn:sdmx:org.sdmx.infomodel.codelist.Codelist=ECB:CL_FREQ(1.0)"); writer.WritePropertyName("codelistRef"); writer.WriteStartObject(); writer.WritePropertyName("id"); writer.WriteValue(x.MaintainableReference.MaintainableId); //writer.WriteValue("CL_FREQ"); writer.WritePropertyName("agencyID"); writer.WriteValue(x.MaintainableReference.AgencyId); writer.WritePropertyName("version"); writer.WriteValue(x.MaintainableReference.Version); writer.WriteEndObject(); writer.WriteEndObject(); } } } //non sempre if (dimensions.ConceptRole != null) { IList<ICrossReference> ConRol = dimensions.ConceptRole; foreach (var xw in ConRol) { var s = xw.MaintainableId; writer.WritePropertyName("conceptRole"); writer.WriteStartObject(); writer.WritePropertyName("FREQUENCY"); writer.WriteStartObject(); writer.WritePropertyName("id"); writer.WriteValue("COMPONENT_ROLES"); writer.WritePropertyName("agencyID"); writer.WriteValue(xw.AgencyId); writer.WritePropertyName("version"); writer.WriteValue(xw.Version); writer.WritePropertyName("conceptID"); writer.WriteValue("FREQUENCY"); writer.WriteEndObject(); writer.WriteEndObject(); } } //------------------ writer.WriteEndObject(); } writer.WriteEndObject(); //////////////////////// // groups////////////// IList<IGroup> gplist = datastructureBean.Groups; if (gplist.Count > 0) { foreach (var gp1 in gplist){ writer.WritePropertyName("groups"); writer.WriteStartObject(); //////////////////////// writer.WritePropertyName("Sibling"); writer.WriteStartObject(); writer.WritePropertyName("id"); writer.WriteValue(gp1.Id); //writer.WriteValue("Sibling"); writer.WritePropertyName("uri"); writer.WriteValue( gp1.Uri); writer.WritePropertyName("position"); writer.WriteValue("0"); writer.WritePropertyName("dimensions"); IList<string> gp12 = gp1.DimensionRefs; writer.WriteStartArray(); foreach (var gppp in gp12) { writer.WriteValue(gppp.ToString()); //writer.WriteValue("REF_AREA"); // writer.WriteValue("ADJUSTMENT"); // writer.WriteValue("STS_INDICATOR"); // writer.WriteValue("STS_ACTIVITY"); // writer.WriteValue("STS_INSTITUTION"); // writer.WriteValue("STS_BASE_YEAR"); } writer.WriteEndArray(); writer.WriteEndObject(); writer.WriteEndObject(); } } //------------------ // writer.WriteEndObject(); /////////////////////// /////////////////////// //attributes/////////// var attributes = datastructureBean.AttributeList; if (!(attributes == null)) { writer.WritePropertyName("attributes"); writer.WriteStartObject(); foreach (var item in attributes.Attributes) { writer.WritePropertyName(item.Id); writer.WriteStartObject(); writer.WritePropertyName("id"); writer.WriteValue(item.Id); writer.WritePropertyName("refclass"); writer.WriteValue("Data Attribute"); writer.WritePropertyName("assignmentStatus"); writer.WriteValue(item.AssignmentStatus); writer.WritePropertyName("attachmentLevel"); writer.WriteValue(item.AttachmentLevel); writer.WritePropertyName("attachmentGroup"); writer.WriteValue(item.AttachmentGroup); var t = item.ConceptRef.AgencyId; writer.WritePropertyName("conceptScheme"); writer.WriteStartObject(); writer.WritePropertyName("id"); writer.WriteValue("STS_SCHEME"); writer.WritePropertyName("agencyID"); writer.WriteValue(item.ConceptRef.AgencyId); writer.WritePropertyName("version"); writer.WriteValue(item.ConceptRef.Version); writer.WritePropertyName("refclass"); writer.WriteValue("Concept"); writer.WritePropertyName("conceptID"); writer.WriteValue(item.ConceptRef.FullId); writer.WriteEndObject(); // var isr3 = item.AllTextTypes; var isr4 = item.DimensionReferences; //foreach (var x in isr3) //{ // ???????????????????????????????????????? writer.WritePropertyName("localRepresentation"); writer.WriteStartObject(); writer.WritePropertyName("textFormat"); writer.WriteStartObject(); writer.WritePropertyName("isMultiLingual"); writer.WriteValue("false"); writer.WritePropertyName("textType"); writer.WriteValue("STRING"); writer.WritePropertyName("isSequence"); writer.WriteValue("false"); writer.WriteEndObject(); writer.WriteEndObject(); // } ///////////////////////// writer.WritePropertyName("attributeRelationship"); if (item.DimensionReferences.Count > 0) { writer.WriteStartObject(); writer.WritePropertyName("dimensions"); writer.WriteStartArray(); for (int i=0; i < item.DimensionReferences.Count; i++){ writer.WriteValue(item.DimensionReferences[i].ToString()); } writer.WriteEndArray(); writer.WriteEndObject(); } else { if (!String.IsNullOrEmpty(item.PrimaryMeasureReference)){ writer.WriteStartObject(); writer.WritePropertyName("primaryMeasure"); writer.WriteValue(item.PrimaryMeasureReference); writer.WriteEndObject(); } //writer.WriteEndObject(); } ////////////////// writer.WriteEndObject(); } /* writer.WriteStartObject(); writer.WritePropertyName("id"); writer.WriteValue("Sibling"); writer.WritePropertyName("uri"); writer.WriteValue(""); writer.WritePropertyName("position"); writer.WriteValue("0"); writer.WritePropertyName("dimensions"); writer.WriteStartArray(); writer.WriteValue("REF_AREA"); writer.WriteValue("ADJUSTMENT"); writer.WriteValue("STS_INDICATOR"); writer.WriteValue("STS_ACTIVITY"); writer.WriteValue("STS_INSTITUTION"); writer.WriteValue("STS_BASE_YEAR"); writer.WriteEndArray(); writer.WriteEndObject(); writer.WriteEndObject(); writer.WriteEndObject(); */ ////////////////////// /////////////////////// //attributes/////////// writer.WriteEndObject(); } IMeasureList mslist = datastructureBean.MeasureList; writer.WritePropertyName("measures"); writer.WriteStartObject(); writer.WritePropertyName(mslist.PrimaryMeasure.ConceptRef.FullId); writer.WriteStartObject(); writer.WritePropertyName("id"); writer.WriteValue(mslist.PrimaryMeasure.ConceptRef.FullId); writer.WritePropertyName("refclass"); writer.WriteValue("Primary Measure"); writer.WritePropertyName("conceptScheme"); writer.WriteStartObject(); writer.WritePropertyName("id"); writer.WriteValue("STS_SCHEME"); writer.WritePropertyName("agencyID"); //mslist.AsReference.AgencyId writer.WriteValue(mslist.PrimaryMeasure.ConceptRef.AgencyId); writer.WritePropertyName("version"); writer.WriteValue(mslist.PrimaryMeasure.ConceptRef.Version); writer.WritePropertyName("refclass"); writer.WriteValue("Concept"); writer.WritePropertyName("conceptID"); writer.WriteValue(mslist.PrimaryMeasure.ConceptRef.FullId); writer.WriteEndObject(); writer.WritePropertyName("localRepresentation"); writer.WriteStartObject(); writer.WritePropertyName("textFormat"); writer.WriteStartObject(); writer.WritePropertyName("isMultiLingual"); writer.WriteValue("false"); writer.WritePropertyName("textType"); writer.WriteValue("?????DOUBLE"); writer.WritePropertyName("isSequence"); writer.WriteValue("false"); writer.WriteEndObject(); writer.WriteEndObject(); writer.WriteEndObject(); // writer.WriteEndObject(); ///////////////////////////// writer.WriteEnd(); writer.WritePropertyName("accessLevel"); writer.WriteValue("PUBLIC"); //writer.WritePropertyName("lastUpdateDate"); //writer.WriteValue(codelistBean.IsExternalReference); writer.WritePropertyName("type"); writer.WriteValue("DSD"); writer.WritePropertyName("canBeMaintained"); writer.WriteValue("true"); // writer.WriteEndObject(); writer.WriteEndArray(); } writer.WriteEndObject(); } } return sw; }
public void Culture() { StringWriter sw = new StringWriter(); JsonTextWriter writer = new JsonTextWriter(sw); writer.Formatting = Formatting.Indented; writer.DateFormatString = "yyyy tt"; writer.Culture = new CultureInfo("en-NZ"); writer.QuoteChar = '\''; writer.WriteStartArray(); writer.WriteValue(new DateTime(2000, 1, 1, 1, 1, 1, DateTimeKind.Utc)); writer.WriteValue(new DateTimeOffset(2000, 1, 1, 1, 1, 1, TimeSpan.Zero)); writer.WriteEnd(); Assert.AreEqual(@"[ '2000 a.m.', '2000 a.m.' ]", sw.ToString()); }
private StringWriter WriteCategoryScheme(ISet<ICategorySchemeObject> categoryscheme, string resourceId, StringWriter sw) { if (categoryscheme.Count > 0) { using (JsonWriter writer = new JsonTextWriter(sw)) { bool isIndented = Convert.ToBoolean(ConfigurationManager.AppSettings["isIndented"]); if (isIndented == true) { writer.Formatting = Newtonsoft.Json.Formatting.Indented; } writer.WriteStartObject(); foreach (ICategorySchemeObject categoryscheme1 in categoryscheme) { writer.WritePropertyName("CGS"); writer.WriteStartArray(); writer.WriteStartObject(); writer.WritePropertyName("id"); writer.WriteValue(categoryscheme1.Id); writer.WritePropertyName("agencyID"); writer.WriteValue(categoryscheme1.AgencyId); writer.WritePropertyName("version"); writer.WriteValue(categoryscheme1.Version); writer.WritePropertyName("stub"); writer.WriteValue("false"); writer.WritePropertyName("isFinal"); writer.WriteValue(categoryscheme1.IsFinal.IsTrue); writer.WritePropertyName("externalReference"); writer.WriteValue(categoryscheme1.IsExternalReference.IsTrue); writer.WritePropertyName("names"); writer.WriteStartObject(); foreach (var item in categoryscheme1.Names) { writer.WritePropertyName(item.Locale); writer.WriteValue(item.Value); } writer.WriteEndObject(); writer.WritePropertyName("descriptions"); writer.WriteStartObject(); foreach (var item in categoryscheme1.Descriptions) { writer.WritePropertyName(item.Locale); writer.WriteValue(item.Value); } writer.WriteEndObject(); writer.WritePropertyName("categories"); writer.WriteStartObject(); foreach (var item in categoryscheme1.Items) { writer.WritePropertyName(item.Id); writer.WriteStartObject(); writer.WritePropertyName("id"); writer.WriteValue(item.Id); writer.WritePropertyName("names"); writer.WriteStartObject(); foreach (var item1 in item.Names) { writer.WritePropertyName(item1.Locale); writer.WriteValue(item1.Value); } writer.WriteEndObject(); writer.WritePropertyName("descriptions"); writer.WriteStartObject(); foreach (var item1 in item.Descriptions) { writer.WritePropertyName(item1.Locale); writer.WriteValue(item1.Value); } writer.WriteEndObject(); writer.WritePropertyName("categories"); writer.WriteStartObject(); foreach (var item1 in item.Items) { writer.WritePropertyName(item1.Id); writer.WriteStartObject(); writer.WritePropertyName("id"); writer.WriteValue(item1.Id); writer.WritePropertyName("refclass"); writer.WriteValue("Category"); writer.WritePropertyName("names"); writer.WriteStartObject(); foreach (var item2 in item1.Names) { writer.WritePropertyName(item2.Locale); writer.WriteValue(item2.Value); } writer.WriteEndObject(); writer.WriteEndObject(); } writer.WriteEndObject(); writer.WriteEndObject(); } // writer.WriteEndObject(); writer.WriteEnd(); writer.WritePropertyName("accessLevel"); writer.WriteValue("PUBLIC"); //writer.WritePropertyName("lastUpdateDate"); //writer.WriteValue(codelistBean.IsExternalReference); writer.WritePropertyName("type"); writer.WriteValue("CGS"); writer.WritePropertyName("canBeMaintained"); writer.WriteValue("true"); writer.WriteEndObject(); writer.WriteEndArray(); } writer.WriteEndObject(); } } return sw; }
public void State() { StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); using (JsonWriter jsonWriter = new JsonTextWriter(sw)) { Assert.AreEqual(WriteState.Start, jsonWriter.WriteState); jsonWriter.WriteStartObject(); Assert.AreEqual(WriteState.Object, jsonWriter.WriteState); Assert.AreEqual("", jsonWriter.Path); jsonWriter.WritePropertyName("CPU"); Assert.AreEqual(WriteState.Property, jsonWriter.WriteState); Assert.AreEqual("CPU", jsonWriter.Path); jsonWriter.WriteValue("Intel"); Assert.AreEqual(WriteState.Object, jsonWriter.WriteState); Assert.AreEqual("CPU", jsonWriter.Path); jsonWriter.WritePropertyName("Drives"); Assert.AreEqual(WriteState.Property, jsonWriter.WriteState); Assert.AreEqual("Drives", jsonWriter.Path); jsonWriter.WriteStartArray(); Assert.AreEqual(WriteState.Array, jsonWriter.WriteState); jsonWriter.WriteValue("DVD read/writer"); Assert.AreEqual(WriteState.Array, jsonWriter.WriteState); Assert.AreEqual("Drives[0]", jsonWriter.Path); jsonWriter.WriteEnd(); Assert.AreEqual(WriteState.Object, jsonWriter.WriteState); Assert.AreEqual("Drives", jsonWriter.Path); jsonWriter.WriteEndObject(); Assert.AreEqual(WriteState.Start, jsonWriter.WriteState); Assert.AreEqual("", jsonWriter.Path); } }
private StringWriter WriteAgenciesScheme(ISet<IAgencyScheme> agencies, string resourceId, StringWriter sw) { if (agencies.Count > 0) { foreach (IAgencyScheme agencie in agencies) { using (JsonWriter writer = new JsonTextWriter(sw)) { //writer.Formatting = Newtonsoft.Json.Formatting.Indented; bool isIndented = Convert.ToBoolean(ConfigurationManager.AppSettings["isIndented"]); if (isIndented == true) { writer.Formatting = Newtonsoft.Json.Formatting.Indented; } writer.WriteStartObject(); writer.WritePropertyName("AGS"); writer.WriteStartArray(); writer.WriteStartObject(); writer.WritePropertyName("id"); writer.WriteValue(agencie.Id); writer.WritePropertyName("agencyID"); writer.WriteValue(agencie.AgencyId); writer.WritePropertyName("version"); writer.WriteValue(agencie.Version); writer.WritePropertyName("stub"); writer.WriteValue(agencie.Version); writer.WritePropertyName("isFinal"); writer.WriteValue(agencie.IsFinal.IsTrue); writer.WritePropertyName("externalReference"); writer.WriteValue(agencie.IsExternalReference.IsTrue); writer.WritePropertyName("names"); writer.WriteStartObject(); foreach (var item in agencie.Names) { writer.WritePropertyName(item.Locale); writer.WriteValue(item.Value); } writer.WriteEndObject(); writer.WritePropertyName("descriptions"); writer.WriteStartObject(); foreach (var item in agencie.Descriptions) { writer.WritePropertyName(item.Locale); writer.WriteValue(item.Value); } writer.WriteEndObject(); writer.WritePropertyName("annotations"); writer.WriteStartObject(); //////////////////////// writer.WritePropertyName("texts"); foreach (var item in agencie.Annotations) { writer.WriteStartObject(); writer.WritePropertyName("texts"); writer.WriteValue(item.Text); writer.WritePropertyName("id"); writer.WriteValue(item.Id); writer.WritePropertyName("title"); writer.WriteValue(item.Title); writer.WriteEndObject(); } //////////////////////// writer.WriteEnd(); writer.WritePropertyName("accessLevel"); writer.WriteValue("PUBLIC"); //writer.WritePropertyName("lastUpdateDate"); //writer.WriteValue(codelistBean.IsExternalReference); writer.WritePropertyName("type"); writer.WriteValue("AGS"); writer.WritePropertyName("canBeMaintained"); writer.WriteValue("true"); writer.WriteEndObject(); writer.WriteEndArray(); writer.WriteEndObject(); } } } return sw; }
public void Path() { StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); string text = "Hello world."; byte[] data = Encoding.UTF8.GetBytes(text); using (JsonTextWriter writer = new JsonTextWriter(sw)) { writer.Formatting = Formatting.Indented; writer.WriteStartArray(); Assert.AreEqual("", writer.Path); writer.WriteStartObject(); Assert.AreEqual("[0]", writer.Path); writer.WritePropertyName("Property1"); Assert.AreEqual("[0].Property1", writer.Path); writer.WriteStartArray(); Assert.AreEqual("[0].Property1", writer.Path); writer.WriteValue(1); Assert.AreEqual("[0].Property1[0]", writer.Path); writer.WriteStartArray(); Assert.AreEqual("[0].Property1[1]", writer.Path); writer.WriteStartArray(); Assert.AreEqual("[0].Property1[1][0]", writer.Path); writer.WriteStartArray(); Assert.AreEqual("[0].Property1[1][0][0]", writer.Path); writer.WriteEndObject(); Assert.AreEqual("[0]", writer.Path); writer.WriteStartObject(); Assert.AreEqual("[1]", writer.Path); writer.WritePropertyName("Property2"); Assert.AreEqual("[1].Property2", writer.Path); writer.WriteStartConstructor("Constructor1"); Assert.AreEqual("[1].Property2", writer.Path); writer.WriteNull(); Assert.AreEqual("[1].Property2[0]", writer.Path); writer.WriteStartArray(); Assert.AreEqual("[1].Property2[1]", writer.Path); writer.WriteValue(1); Assert.AreEqual("[1].Property2[1][0]", writer.Path); writer.WriteEnd(); Assert.AreEqual("[1].Property2[1]", writer.Path); writer.WriteEndObject(); Assert.AreEqual("[1]", writer.Path); writer.WriteEndArray(); Assert.AreEqual("", writer.Path); } Assert.AreEqual(@"[ { ""Property1"": [ 1, [ [ [] ] ] ] }, { ""Property2"": new Constructor1( null, [ 1 ] ) } ]", sb.ToString()); }
private StringWriter WriteCategorisation(ISet<ICategorisationObject> categorisations, string resourceId, StringWriter sw) { if (categorisations.Count > 0) { using (JsonWriter writer = new JsonTextWriter(sw)) { //writer.Formatting = Newtonsoft.Json.Formatting.Indented; bool isIndented = Convert.ToBoolean(ConfigurationManager.AppSettings["isIndented"]); if (isIndented == true) { writer.Formatting = Newtonsoft.Json.Formatting.Indented; } writer.WriteStartObject(); foreach (ICategorisationObject categorisation in categorisations) { writer.WritePropertyName("CTS"); writer.WriteStartArray(); writer.WriteStartObject(); writer.WritePropertyName("id"); writer.WriteValue(categorisation.Id); writer.WritePropertyName("agencyID"); writer.WriteValue(categorisation.AgencyId); writer.WritePropertyName("version"); writer.WriteValue(categorisation.Version); writer.WritePropertyName("stub"); writer.WriteValue("???false"); writer.WritePropertyName("isFinal"); writer.WriteValue(categorisation.IsFinal.IsTrue); writer.WritePropertyName("externalReference"); writer.WriteValue(categorisation.IsExternalReference.IsTrue); writer.WritePropertyName("names"); writer.WriteStartObject(); foreach (var item in categorisation.Names) { writer.WritePropertyName(item.Locale); writer.WriteValue(item.Value); } writer.WriteEndObject(); writer.WritePropertyName("categoryReference"); writer.WriteStartObject(); //////////////////////// writer.WritePropertyName("categoryId"); writer.WriteValue(categorisation.CategoryReference.FullId); writer.WritePropertyName("categoryScheme"); writer.WriteStartObject(); writer.WritePropertyName("id"); writer.WriteValue(categorisation.CategoryReference.MaintainableId); writer.WritePropertyName("agencyID"); writer.WriteValue(categorisation.CategoryReference.AgencyId); writer.WritePropertyName("version"); writer.WriteValue(categorisation.CategoryReference.Version); writer.WriteEndObject(); //////////////////////// writer.WritePropertyName("dataflowReference"); writer.WriteStartObject(); //////////////////////// writer.WritePropertyName("id"); writer.WriteValue(categorisation.StructureReference.MaintainableId); writer.WritePropertyName("agencyID"); writer.WriteValue(categorisation.StructureReference.AgencyId); writer.WritePropertyName("version"); writer.WriteValue(categorisation.StructureReference.Version); //////////////////////// writer.WriteEnd(); writer.WritePropertyName("accessLevel"); writer.WriteValue("PUBLIC"); //writer.WritePropertyName("lastUpdateDate"); //writer.WriteValue(codelistBean.IsExternalReference); writer.WritePropertyName("type"); writer.WriteValue("CTS"); writer.WritePropertyName("canBeMaintained"); writer.WriteValue("true"); writer.WriteEndObject(); writer.WriteEndArray(); } writer.WriteEndObject(); } } return sw; }