具有 ID 和名称的 JSON 字符串?使用 C 夏普

json string having id and name? using c sharp

本文关键字:字符串 使用 夏普 JSON ID 具有      更新时间:2023-09-26

这是我的 JSON 字符串

 var people = '{"Id": 101020001 ,  "Title": "subsidary","Id": 103010001 ,  "Title": "LOAN FROM BANK ?","Id": 104010001 ,  "Title": "FAWAD","Id": 104010002 ,  "Title": "GETING","Id": 104010003}

我把它建为

     string MyDictionaryToJson(Dictionary<int, string > dict)
       {
     var entries = dict.Select(d =>
         string.Format("'"Id'": {0} ,  '"Title'": '"{1}'"", d.Key, string.Join(",", d.Value)));
     return "{" + string.Join(",", entries) + "}";
 }

但是我想填充剑道网格,所以ID未知,我想要那样

"{"Id":"101020001" , "Title":"titlesubsidary"},{"Id":"101020002" , "Title":"titlenext"}, {"Id":"101020003" , "Title":"titleagain"}

剑道组合盒

    var people = '<%=jsonS %>'
  $('#Text1').kendoComboBox({
       dataTextField: 'Title',
      dataValueField: 'Id',
      template: "<table><tr><td width='100px'>${ Id}</td><td width='100px'>${ Title }</td></tr></table>",
      dataSource: { data: people }
  });
错误:

引用错误:未定义 ID

因为您的 Json 字符串无效。您不应手动构建它。尝试使用 Json.NET。如果你想chceck如何将Json编译到对象,你可以使用json2csharp。