R
Rinaldo1961
Guest
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.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
Continue reading...
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.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
Continue reading...