所以目前我正在开发一个 WebAPI 并且运行时出现以下错误。
当我尝试返回一个用 JsonConvert.SerializeObject(object) 序列化的 List 时,我的第二个属性(字符串 JSON)被回车和换行符掩盖了。
这是代码:
public class Template
{
public string Name;
public string JSON;
}
public HttpResponseMessage GetAll()
{
var items = db.GetTemplates().ToList<Template>();
var resp = new HttpResponseMessage()
{
Content = new StringContent(JsonConvert.SerializeObject(items),Encoding.UTF8,"application/json")
};
resp.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
return resp;
}
Run Code Online (Sandbox Code Playgroud)
更改为:
Content = new StringContent(JsonConvert.SerializeObject(items.ToList<Template>()[0]),Encoding.UTF8,"application/json")
Run Code Online (Sandbox Code Playgroud)
显示同样的错误
在将代码更改为:
Content = new StringContent(JsonConvert.SerializeObject(items.ToList<Template>()[0].JSON),Encoding.UTF8,"application/json")
Run Code Online (Sandbox Code Playgroud)
一切恢复正常...
在浏览器中检查,而不是在 Visual Studio 中!
有人给我提示吗?谷歌只是不会让我找到答案。
提前致谢!
我使用的是WindowsPhone Toolkit的ExpanderView,在第一次加载时,扩展的Expander总是看起来像第二张图片.看起来,它始终处于所有物品的同一高度.
如果我转到另一页并返回,一切都会很好,布局看起来很安静 - 除了停止扩展器的行(图1).
this.UpdatedLayout();(当前页面)或ExpanderView.UpdateLayout(); 解决了什么.未显示的项目已在该列表中完全加载.


<ItemsControl ItemsSource="{Binding EpisodeList}" Margin="20,0,0,0" Grid.Row="1" Grid.ColumnSpan="2">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<toolkit:ExpanderView ItemsSource="{Binding Value}" >
<toolkit:ExpanderView.Header>
<TextBlock Margin="0,0,10,0">
<Run Text="Season "/>
<Run Text="{Binding Key}" />
</TextBlock>
</toolkit:ExpanderView.Header>
<toolkit:ExpanderView.ItemTemplate>
<DataTemplate>
<Border BorderBrush="White" BorderThickness="1" Margin="5">
<Grid MouseLeftButtonUp="Grid_MouseLeftButtonUp">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Image Height="40" Source="{Binding ScreenCap}" Margin="5,0,0,0"/>
<TextBlock x:Name="t" Margin="10" Text="{Binding Title}" TextWrapping="Wrap" Grid.Column="1" />
</Grid>
</Border>
</DataTemplate>
</toolkit:ExpanderView.ItemTemplate>
</toolkit:ExpanderView>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Run Code Online (Sandbox Code Playgroud)
EpisodeList是Dictionary(int,ObservableCollection(myClass))的类型,并实现了INotifyPropertyChanged
如果有人有任何计划在这里出错,我真的很感激你的帮助,我只是没有在谷歌上找到任何bug报告,也没有类似的Bug.
(在设备和仿真器上调试)