在ObservableCollection(C#uwp)中转换

在ObservableCollection(C#uwp)中转换,c#,data-binding,uwp,C#,Data Binding,Uwp,我正在为UWP编写一个应用程序 根据这个答案,我尝试使用数据绑定 以下是我的课程: public class Billing { public string first_name { get; set; } public string last_name { get; set; } public string company { get; set; } public string address_1 { get; set;

我正在为UWP编写一个应用程序

根据这个答案,我尝试使用数据绑定

以下是我的课程:

 public class Billing
    {
        public string first_name { get; set; }
        public string last_name { get; set; }
        public string company { get; set; }
        public string address_1 { get; set; }
        public string address_2 { get; set; }
        public string city { get; set; }
        public string state { get; set; }
        public string postcode { get; set; }
        public string country { get; set; }
        public string email { get; set; }
        public string phone { get; set; }          
    }

    public class Shipping
    {
        public string first_name { get; set; }
        public string last_name { get; set; }
        public string company { get; set; }
        public string address_1 { get; set; }
        public string address_2 { get; set; }
        public string city { get; set; }
        public string state { get; set; }
        public string postcode { get; set; }
        public string country { get; set; }
    }

    public class RootObject
    {
        public int id { get; set; }
        public int parent_id { get; set; }
        public string status { get; set; }

        public string order_key { get; set; }
        public string currency { get; set; }
        public string version { get; set; }
        public bool prices_include_tax { get; set; }
        public string date_created { get; set; }
        public string date_modified { get; set; }
        public int customer_id { get; set; }
        public double discount_total { get; set; }
        public double discount_tax { get; set; }
        public double shipping_total { get; set; }
        public double shipping_tax { get; set; }
        public double cart_tax { get; set; }
        public double total { get; set; }
        public double total_tax { get; set; }
        public Billing billing { get; set; }
        public Shipping shipping { get; set; }
        public string payment_method { get; set; }
        public string payment_method_title { get; set; }
        public string transaction_id { get; set; }
        public string customer_ip_address { get; set; }
        public string customer_user_agent { get; set; }
        public string created_via { get; set; }
        public string customer_note { get; set; }
        public string date_completed { get; set; }
        public string date_paid { get; set; }
        public string cart_hash { get; set; }
        public List<object> line_items { get; set; }
        public List<object> tax_lines { get; set; }
        public List<object> shipping_lines { get; set; }
        public List<object> fee_lines { get; set; }
        public List<object> coupon_lines { get; set; }
    }

    public ObservableCollection<RootObject> Orders { get; set; }
公共类计费
{
公共字符串first_name{get;set;}
公共字符串last_name{get;set;}
公共字符串公司{get;set;}
公共字符串地址_1{get;set;}
公共字符串地址_2{get;set;}
公共字符串city{get;set;}
公共字符串状态{get;set;}
公共字符串邮政编码{get;set;}
公共字符串国家{get;set;}
公共字符串电子邮件{get;set;}
公用字符串电话{get;set;}
}
公舱航运
{
公共字符串first_name{get;set;}
公共字符串last_name{get;set;}
公共字符串公司{get;set;}
公共字符串地址_1{get;set;}
公共字符串地址_2{get;set;}
公共字符串city{get;set;}
公共字符串状态{get;set;}
公共字符串邮政编码{get;set;}
公共字符串国家{get;set;}
}
公共类根对象
{
公共int id{get;set;}
public int parent_id{get;set;}
公共字符串状态{get;set;}
公共字符串顺序_键{get;set;}
公共字符串货币{get;set;}
公共字符串版本{get;set;}
公营房屋价格含税{get;set;}
公共字符串日期_创建{get;set;}
公共字符串date_modified{get;set;}
public int customer_id{get;set;}
公共双折扣_总计{get;set;}
公共双重折扣税{get;set;}
公共双配送_总计{get;set;}
公共双重运输税{get;set;}
公共双车税{get;set;}
公共双总计{get;set;}
公共双重总税{get;set;}
公共账单{get;set;}
公共传送{get;set;}
公共字符串支付方法{get;set;}
公共字符串支付方法标题{get;set;}
公共字符串事务_id{get;set;}
公共字符串customer_ip_address{get;set;}
公共字符串customer\u user\u agent{get;set;}
通过{get;set;}创建的公共字符串
公共字符串customer_note{get;set;}
公共字符串日期_已完成{get;set;}
公共字符串日期{get;set;}
公共字符串cart_hash{get;set;}
公共列表行_项{get;set;}
公共列表税_行{get;set;}
公共列表传送线{get;set;}
公共列表费_行{get;set;}
公共列表优惠券_行{get;set;}
}
公共可观察收集顺序{get;set;}
代码如下:

List<RootObject> rootObjectData = JsonConvert.DeserializeObject<List<RootObject>>(products);
foreach (RootObject root in rootObjectData)
{
    string date = root.date_created;
    string name = root.billing.first_name + root.billing.last_name ;
    Orders = new ObservableCollection<RootObject> { new RootObject { date_created = date,billing = name } };
}
List rootObjectData=JsonConvert.DeserializeObject(产品);
foreach(rootObjectData中的rootobjectroot)
{
字符串日期=root.date\u已创建;
字符串名称=root.billing.first\u name+root.billing.last\u name;
Orders=new ObservableCollection{new RootObject{date_created=date,billing=name};
}
使用
billing=name
时,我有一个错误:
无法将类型“string”隐式转换为“Milano.InWork.billing”

如何修复此错误? 也许这很简单,但我没有找到解决办法。 谢谢你的帮助

对于billing=name,我有以下错误:无法将类型“string”隐式转换为“Milano.InWork.billing”

当然会发生此错误,类
RootObject
中的
billing
具有数据类型
billing
,这是您定义的另一个类


仅从您的代码中,我认为您只想在
根目录中以字符串形式显示
名和
姓,然后您可以将
根目录对象中的代码
公共账单{get;set;}
更改为
公共账单{get;set;}

您正在尝试将字符串值分配给RootObject。当然,这不可能。好吧,我怎样才能修复它?@Pierre Louppagniez在我看来,您试图反序列化的JSON数据存在一些问题。JSON根上的“billing”属性的内容是什么?例如
“billing”:{“first_name”:“John”,“last_name”:“Doe”,“company”:“address_1”:“969 Market”,“address_2”:“city”:“San Francisco”,“state”:“CA”,“postcode”:“94103”,“country”:“US”,“email”:“约翰。doe@example.com“,”电话“:”(555)555-5555“},
@Aldinesampaio当您尝试将
root.billing.first\u name+root.billing.last\u name
设置为计费对象时,结果会是什么样的?如
billing billing=“JohnDoe”