简体   繁体   English

C# (Xamarin) 如何将 JSON 写入数组?

[英]C# (Xamarin) How to write JSON to array?

I have output in JSON.我在 JSON 中有 output。

{
  "id": null,
  "kkt": [],
  "CallNumber": null,
  "CallDuration": null,
  "CallDurationFormat": "00:00:00",
  "CallDateTick": 0,
  "CallDate": "1970-01-01T00:00:00Z",
  "CallType": null,
  "CallDescription": "01/01/1970 12:00 a. m. -  | Duración: 00:00:00"
}

I want to write Call specification to kkt array like that:我想像这样将调用规范写入 kkt 数组:

{
  "id": null,
  "kkt": [
{

  "CallNumber": null,
  "CallDuration": null,
  "CallDurationFormat": "00:00:00",
  "CallDateTick": 0,
  "CallDate": "1970-01-01T00:00:00Z",
  "CallType": null,
  "CallDescription": "01/01/1970 12:00 a. m. -  | Duración: 00:00:00"

}
],
}

For achieve this I created class Calls that I want serialize, but I dont know how to create List<> so that the specifications are in array.为了实现这一点,我创建了 class 我想要序列化的调用,但我不知道如何创建 List<> 以便规范在数组中。

Do someone have idea how I can write List<> or do something else to achieve that Call specs will be in kkt array?有人知道我如何编写 List<> 或做其他事情来实现调用规范将在 kkt 数组中吗?

Thank you for advices!谢谢指教!


Classes:班级:

CallLogModel: https://pastebin.com/nLeLszW0 CallLogModel: https://pastebin.com/nLeLszW0

CallLog: https://pastebin.com/fvS6s4SQ通话记录: https://pastebin.com/fvS6s4SQ

ICallLog: https://pastebin.com/tz2uxDXw ICallLog: https://pastebin.com/tz2uxDXw

Calls: https://pastebin.com/EWFgm2jx来电: https://pastebin.com/EWFgm2jx

LoadCallLog() method: https://pastebin.com/VATQnGG5 LoadCallLog() 方法: https://pastebin.com/VATQnGG5

Try to change like below:尝试像下面这样改变:

Calls model: Calls model:

public class Calls 
{

    public string id;
    public List<CallLogModel> kkt;
}

ICallLog interface: ICallLog接口:

public interface ICallLog
{
    List<CallLogModel> GetCallLogs();
}

then in your LoadCallLog() method you need to add the value that you queried into the Calls model like:然后在您的LoadCallLog()方法中,您需要将查询的值添加到Calls model 中,例如:

var Logg = DependencyService.Get<ICallLog>().GetCallLogs();

if (!(Preferences.ContainsKey("GUID")))
   {
       Preferences.Set("GUID", App.newUser1);
   }
 var a = Preferences.Get("GUID", "hovno"); //if this is the id of Calls model
 Calls calls = new Calls();
 calls.id = a;
 calls.kkt = Logg;
 var serialized = JsonConvert.SerializeObject(calls);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM