Newtonsoft.JSON serializeobject返回空的JSON字符串 [英] Newtonsoft.JSON serializeobject returns empty JSON string
问题描述
每个人都有很多问题,我几乎尝试了所有方法,但对我来说都不起作用.
Everyone got this question a lot, and I tried almost everything but none of it works for me.
因此,我正在Xamarin.Forms中进行开发,即将把我的数据发送到服务器.我有这个课:
So I am developing in Xamarin.Forms and is about to send my data to the server. I have this class:
public class Customer
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string BirthDate { get; set; }
public string Password { get; set; }
public string EmailAddress { get; set; }
public string ContactNumber { get; set; }
}
然后我使用了Newtonsoft的SerializeObject方法:
Then I used Newtonsoft's SerializeObject method:
Customer customer = new Customer
{
FirstName = FirstName.Text,
LastName = LastName.Text,
BirthDate = BirthDate.Date.ToString(),
EmailAddress = Email.Text,
Password = Password.Text,
ContactNumber = Mobile.Text
};
var item = JsonConvert.SerializeObject(customer);
但是变量item
会导致包含空JSON对象{}
的字符串.我的实现有问题吗?
But variable item
results in a string containing an empty JSON object {}
. Is something wrong with my implementation?
另外,我注意到,尽管我的Customer类及其成员是公共的,但调试器仍将它们视为非公共"成员.请参阅调试器的屏幕截图":
Also, I noticed that although my Customer class and its members are public, the debugger still counts them as "non-public" members. Please see "screenshot of debugger":
推荐答案
Xamarin Live Player似乎与序列化程序有关.我尝试通过USB插入手机,并且可以正常工作!
It appears that Xamarin Live Player has some issues with the serializer. I tried plugging my phone via USB and it works!
这篇关于Newtonsoft.JSON serializeobject返回空的JSON字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!