在Repeater,ASP.NET中显示JSON数据

时间:2014-02-20 10:58:41

标签: c# asp.net .net

我将一个类序列化为一个JSON对象,然后对其进行反序列化并将其作为数据源对象传递给Repeater。使用.NET 4.5的新模型绑定功能,我可以按如下方式显示内容:

     <asp:Repeater runat="server" ID="rptResults" ItemType="BTSanctions.Global.Models.Entity">
      <ItemTemplate>
         <div class="Results">
            <asp:Label runat="server" ID="lblMessageId" Visible="false" Text='<%#: Item.MessageId %>'></asp:Label>
            <p><strong>Countries:&nbsp;</strong><asp: ID="ListOfCountries"  runat="server" Text='<%# Item.Countries %>'></asp:></p>
            <p><strong>Matched Percent:&nbsp;</strong><asp:Label runat="server" ID="lblMatchedPercent"></asp:Label></p>                               
            <p><strong>Search String:&nbsp;</strong><asp:Literal ID="ltSearchString" runat="server" Text='<%#: Item.SearchedString %>'></asp:Literal>
            <p><strong>Matched On:&nbsp;</strong><asp:literal ID="ltMatchedOn" runat="server" Text='<%#: Item.MatchedString %>'></asp:literal></p> 
         </div>
       </ItemTemplate>
     </asp:Repeater>

因此,MessageId,Matched Percentage,Search String和Matched On是单个值,但Countries是一个数组。我不确定如何,即使可以在转发器中创建它们。

我的JSON字符串是:

{"Aka":["Wayne"],"Countries":["United States: 1","United States: 2"]"PercentageMatch":100,"SearchedString":"Wayne","MatchedString":"Wayne"}

修改

  [Serializable]
  public class Entity
  {
    public string MessageId { get; set; }
    public List<string> Aka;
    public List<string> Countries;
    public string Id { get; set; }
    public string ItemType { get; set; }
    public string DateListed { get; set; }
    public string Gender { get; set; }
    public string List { get; set; }
    public List<string> IdentNumbers;
    public List<string> ListingReasons;
    public List<string> Names;
    public int PercentageMatch { get; set; }
    public string SearchedString { get; set; }
    public string MatchedString { get; set; }
    public string Sender { get; set; } 
  }

0 个答案:

没有答案