您可以在后面的代码中将它们拆分为两个字段
// Let I have two properties on my page as
protected string ImageUrl { get; set; }
protected string Name { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
// Suppose I have the value in a string variable val
string val = " {Name:'bla bla', ImageUrl:'www.myimago.gif'}";
// Split them using String.Split function
string[] array = val.Split(',');
ImageUrl = array[1].Replace('}',' ');
Name = array[0].Replace('{',' ');
}
// aspx source code
<%= Name %> // Output: Name:'bla bla'
<%= ImageUrl %> // Output: ImageUrl:'www.myimago.gif'
或者如果你只想要 ImageURL 那么你可以从你的 sql 查询中只返回 ImageURL 作为
Declare @var varchar(50)
set @var = '{Name:"bla bla", ImageUrl:"www.myimago.gif"}'
select SUBSTRING(@var, CHARINDEX('ImageUrl:',@var,0) ,LEN(@var) - CHARINDEX('ImageUrl:',@var,0)) as [Image URL]
// Output: ImageUrl:"www.myimago.gif"