您可以將它們在後面的代碼分成兩個領域
// 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那麼你可以爲
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"
爲什麼從你的SQL查詢僅返回IMAGEURL不把它們分成代碼? –