C#拼接长字符串,根据是否查询到值来动态赋值。

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010481239/article/details/78940658
//查询语句写在这
                    try
                    {
                        while (reader.Read())
                        {
                            if (reader.HasRows)
                            {
    JSONstring += "{";
    JSONstring += "\"" + "wx_id" + "\":\"" + reader.GetString("wx_id") + "\",";
    beNeck = reader.GetString("beNeck");
            if (beNeck != "0")
             {                                    
        JSONstring += "\"" + "beNeck" + "\":\"" + reader.GetString("beNeck") + "\",";
        JSONstring += "\"" + "neckN" + "\":\"" + reader.GetString("neckN") + "\",";
        JSONstring += "\"" + "neckCR" + "\":\"" + reader.GetString("neckCR") + "\",";
        JSONstring += "\"" + "neckRAN" + "\":\"" + reader.GetString("neckRAN") + "\",";
        JSONstring += "\"" + "neckRSN" + "\":\"" + reader.GetString("neckRSN") + "\",";
        JSONstring += "\"" + "neckChN" + "\":\"" + reader.GetString("neckChN") + "\",";
             }
             beShoulderW = reader.GetString("beShoulderW");
           if (beShoulderW != "0")
             {
JSONstring += "\"" + "beShoulderW"+ "\":\"" + reader.GetString("beShoulderW") + "\",";
JSONstring += "\"" + "shoulderWN" + "\":\"" + reader.GetString("shoulderWN") + "\",";
JSONstring += "\"" + "shoulderWCR" + "\":\"" + reader.GetString("shoulderWCR") + "\",";
JSONstring += "\"" + "shoulderWRAN" + "\":\"" + reader.GetString("shoulderWRAN") + "\",";
JSONstring += "\"" + "shoulderWRSN" + "\":\"" + reader.GetString("shoulderWRSN") + "\",";
JSONstring += "\"" + "shoulderWChN" + "\":\"" + reader.GetString("shoulderWChN") + "\",";
              }
               JSONstring = JSONstring.TrimEnd(specialChars);
               JSONstring += "},";
               JSONstring = JSONstring.TrimEnd(specialChars);
               JSONstring += "]";                    
                            }
                        }
                    }
                    catch
                    {              
                        reader.Close();
                    }
                    finally
                    {              
                        reader.Close();
                    }
                      Response.Write(MysqlHelper.Encrypt(JSONstring));

猜你喜欢

转载自blog.csdn.net/u010481239/article/details/78940658