Ejemplo n.º 1
0
        public static string GetJson(DBgl_UserInfoCollection 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(DBgl_UserInfo objItem)
                    {
                        jsonWriter.WriteStartObject();
                        jsonWriter.WritePropertyName("UserInfId");
                        jsonWriter.WriteValue(objItem.UserInfId.ToString());
                        jsonWriter.WritePropertyName("UserId");
                        jsonWriter.WriteValue(objItem.UserId.ToString());
                        jsonWriter.WritePropertyName("UserName");
                        jsonWriter.WriteValue(objItem.UserName.ToString());
                        jsonWriter.WritePropertyName("CreatedDate");
                        jsonWriter.WriteValue(objItem.CreatedDate.ToString());
                        jsonWriter.WritePropertyName("Mobile");
                        jsonWriter.WriteValue(objItem.Mobile.ToString());
                        jsonWriter.WritePropertyName("CountryId");
                        jsonWriter.WriteValue(objItem.CountryId.ToString());
                        //jsonWriter.WritePropertyName("LocationId");
                        //jsonWriter.WriteValue(objItem.LocationId.ToString());
                        jsonWriter.WritePropertyName("Address");
                        jsonWriter.WriteValue(objItem.Address.ToString());
                        jsonWriter.WritePropertyName("Rating");
                        jsonWriter.WriteValue(objItem.Rating.ToString());
                        jsonWriter.WritePropertyName("MyLegs");
                        jsonWriter.WriteValue(objItem.MyLegs.ToString());
                        jsonWriter.WritePropertyName("EnjoyLegs");
                        jsonWriter.WriteValue(objItem.EnjoyLegs.ToString());
                        jsonWriter.WritePropertyName("Sex");
                        jsonWriter.WriteValue(objItem.Sex.ToString());


                        jsonWriter.WritePropertyName("UserImg");
                        DBtblUser myUser;
                        string img = "no_image.gif";
                        myUser     = DBtblUserManager.GetItemByID(objItem.UserId);
                        if (myUser != null)
                        {
                            img = myUser.ImgUrl;
                        }
                        jsonWriter.WriteValue(img);

                        jsonWriter.WritePropertyName("createdUser");
                        jsonWriter.WriteValue(objItem.createdUser.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());
        }