如何从服务器中排除数据以解析JSON?

时间:2016-03-20 17:17:24

标签: java android json parsing

这是我从服务器获得的响应,

:ok

event: data
data: {"target":42,"data": `{"text":"string","numer":0,"id":1234214214,"likes":0,"isNewInstance":true,"created":1458493863596,"edited":1458493863596},"type":"create"}`

但是,JSON的唯一部分是

{"text":"string","numer":0,"id":1234214214,"likes":0,"isNewInstance":true,"created":1458493863596,"edited":1458493863596},"type":"create"}

所以我想排除

:ok

event: data
data:
每次我尝试从服务器解析时,从我的解析

如何排除这个?

1 个答案:

答案 0 :(得分:1)

我同意服务器的更正,直到您可以执行该修补程序:

public class FirstLastDataTemplateSelector : DataTemplateSelector
{
    public DataTemplate DefaultTemplate { get; set; }
    public DataTemplate FirstItemTemplate { get; set; }
    public DataTemplate LastItemTemplate { get; set; }

    protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
    {
        var lv = GetListView(container);
        if (lv != null)
        {
            var i = lv.Items.IndexOf(item);
            if (i == 0)
            {
                return FirstItemTemplate;
            }
            else if (i == lv.Items.Count - 1)
            {
                return LastItemTemplate;
            }
        }
        return DefaultTemplate;
    }


    public static ListView GetListView(DependencyObject element)
    {
        var parent = VisualTreeHelper.GetParent(element);
        if (parent == null)
        {
            return null;
        }
        var parentListView = parent as ListView;
        return parentListView ?? GetListView(parent);
    }
}

这将打印出来:

  

{“target”:42,“data”:`{“text”:“string”,“numer”:0,“id”:1234214214,“likes”:0,“isNewInstance”:true,“created” “:1458493863596,” 编辑 “:1458493863596},” 类型 “:” 创建“}