示例#1
0
        public static string GetJson(DBtblHouseBankingCollection itemCollection)
        {
            StringBuilder builder = new StringBuilder();

            if (itemCollection.Count > 0)
            {
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                System.IO.StringWriter    sw = new System.IO.StringWriter(sb);
                using (JsonWriter jsonWriter = new JsonTextWriter(sw))
                {
                    jsonWriter.Formatting = Formatting.Indented;
                    jsonWriter.WriteStartObject();
                    jsonWriter.WritePropertyName("results");
                    jsonWriter.WriteStartArray();
                    itemCollection.ForEach(delegate(DBtblHouseBanking objItem)
                    {
                        jsonWriter.WriteStartObject();
                        jsonWriter.WritePropertyName("HouseCode");
                        jsonWriter.WriteValue(objItem.HouseCode.ToString());
                        jsonWriter.WritePropertyName("HPrice");
                        jsonWriter.WriteValue(objItem.HPrice.ToString());
                        jsonWriter.WritePropertyName("HLength");
                        jsonWriter.WriteValue(objItem.HLength.ToString());
                        jsonWriter.WritePropertyName("HWidth");
                        jsonWriter.WriteValue(objItem.HWidth.ToString());
                        jsonWriter.WritePropertyName("BRate");
                        jsonWriter.WriteValue(objItem.BRate.ToString());
                        jsonWriter.WritePropertyName("BYear");
                        jsonWriter.WriteValue(objItem.BYear.ToString());
                        jsonWriter.WritePropertyName("BMonth");
                        jsonWriter.WriteValue(objItem.BMonth.ToString());
                        jsonWriter.WritePropertyName("CreatedUser");
                        jsonWriter.WriteValue(objItem.CreatedUser.ToString());
                        jsonWriter.WritePropertyName("CreatedDate");
                        jsonWriter.WriteValue(objItem.CreatedDate.ToString());

                        jsonWriter.WriteEndObject();
                    });
                    jsonWriter.WriteEndArray();

                    jsonWriter.WriteEndObject();
                    builder.AppendLine(sw.ToString());
                }
            }
            else
            {
                // builder.AppendLine(@"{""results"":[{""id"":""-1"",""myvalue"":""" + MainFunction.ngonngu("gl.nodata") + @"""}]}");
            }
            return(builder.ToString());
        }