none
Json serialize and deserialize filling an autocompletetextbox RRS feed

  • Question

  • Hi,

    I have the source for a autocompletetextbox using json. In row[] is the placeholder of the to sell items. I add it into a list and try to deserialize it with json. Between the items i add a "-" for separate.

    The error i get is System.ArgumentException invalid json primitive <name of the item>

    The code is as followed

    if (helper.Load(commandText, "") == true)
                {
                    if (helper.DataSet.Tables[0].Rows.Count == 0) return;
                    dataRow = helper.DataSet.Tables[0].Rows[0];
    
                    int i = 0;
                    foreach (DataRow row in helper.DataSet.Tables[i].Rows)
                    {
                        string str = row[0].ToString();
                        if (str == string.Empty)
                        {
                            i++;
                            continue;
    
                        }
                        if (Convert.ToDecimal(row[3]) == 0)
                        {
                            i++;
                            continue;
                        }
                        string str1 = row[1].ToString();
                        lijst.Add(str + " - " + str1);
                        vergelijk.Add(str + " - " + str1);
                        BTW.Add(Convert.ToDecimal(row[2]));
                        i++;
                    }
                    if (i > 0)
                    {
                        List<Station> stations = new List<Station>();
                        JavaScriptSerializer json = new JavaScriptSerializer();
    
                        lijst.Sort();
                        //string[] l = new string[lijst.Count];
    
                        tbUitvoorraad1.Items.Clear();
    
                       
                        for (int j = 0; j < lijst.Count; j++)
                        {
                            // l[j] = lijst[j];
                            stations = json.Deserialize<List<Station>>(lijst[j]);
                        }
                        
                        //tbUitvoorraad.AutoCompleteCustomSource.AddRange(l);
                        
                        
                        tbUitvoorraad1.Items.AddRange(stations.ToArray());
                        tbUitvoorraad1.DropHeight = 120;
                        tbUitvoorraad1.ValueMember = "Code";
                        tbUitvoorraad1.DisplayMember = "ChineseName";
    
                        this.tbUitvoorraad1.Match += (o, eve) =>
                        {
                            Station obj = eve.Item as Station;
    
                            if (obj.ThreedLetterCode.StartsWith(eve.MatchText) || obj.ChineseName.StartsWith(eve.MatchText)
                                                                               || obj.SimplePinYin.StartsWith(eve.MatchText) || obj.FullPinYin.StartsWith(eve.MatchText))
                            {
                                eve.MatchResult = true;
                            }
    

    The class Station called by the method

       public class Station
        {
            /// <summary>
            /// 三字母缩写
            /// </summary>
            public string ThreedLetterCode
            {
                get;
                set;
            }
    
            /// <summary>
            /// 中文名
            /// </summary>
            public string ChineseName
            {
                get;
                set;
            }
    
            /// <summary>
            /// 车站编码
            /// </summary>
            public string Code
            {
                get;
                set;
            }
    
            /// <summary>
            /// 全拼
            /// </summary>
            public string FullPinYin
            {
                get;
                set;
            }
    
            /// <summary>
            /// 拼音首字母缩写
            /// </summary>
            public string SimplePinYin
            {
                get;
                set;
            }
    
            /// <summary>
            /// 排序号
            /// </summary>
            public int Index
            {
                get;
                set;
            }
        }

    I hope somebody who can help me, the comment are Chinese and i can't read it.

    Greeting Rinaldo


    Greetings from Amsterdam the Netherlands

    • Moved by CoolDadTx Monday, November 12, 2018 2:58 PM ASP.NET related
    Monday, November 12, 2018 7:54 AM

All replies

  • Autocompletetextbox? This sounds like a web application. This forum is for C#-specific questions.

    Please post questions about ASP.NET in the ASP.NET forums. If your question is related to Winforms or WPF then please post the question in their forums instead.


    Michael Taylor http://www.michaeltaylorp3.net

    Monday, November 12, 2018 2:58 PM
  • Michael this is a c sharp questions


    Greetings from Amsterdam the Netherlands

    Monday, November 12, 2018 3:12 PM