0
我试图反序列化使用C++/CLIC++/CLI类和IList的
[
{
"id":"046e075ad92684",
"NfcA":{
"maxTransceiveLength":253,
"sak":0,
"atqa":"4400",
"timeout":618
},
"Ndef":[
{
"records":[
{
"id":"",
"tnf":1,
"type":"54",
"payload":"02656e48656c6c6f206d792041737365742049442069733a20303030303031"
}
]
}
],
"tech":[
"android.nfc.tech.NfcA",
"android.nfc.tech.MifareUltralight",
"android.nfc.tech.Ndef"
],
"time":1472468356002
}
]
以下JSON我已宣布,以获得JSON数据的内容,下面的类。
ref class tech {
public: String^ tech1;
public: String^ tech2;
public: String^ tech3;
};
ref class Record {
public: String^ id;
public: int tnf;
public: String^ type;
public: String^ payload;
};
ref class Topic_nfc {
public: String^ id;
public: ref class NfcA {
public: int maxTransceiveLength;
public: int sak;
public: int atqa;
public: int timeout;
};
public: ref class Ndef {
public: System::Collections::Generic::IList<Record^>^ records;
};
public: System::Collections::Generic::IList<Ndef^>^ Ndef;
public: System::Collections::Generic::IList<String^>^ tech;
public: unsigned long long time;
public:
NfcA^ NfcA;
};
反序列化后,我可以访问ID和maxTransceiveLength正常使用
printf("MyRawdata[i]->id : %s\n", MyRawdata[i]->id);
printf("MyRawdata[i]->NfcA->maxTransceiveLength : %d\n", MyRawdata[i]->NfcA->maxTransceiveLength);
其中MyRawdata
从
System::Collections::Generic::IList<Topic_nfc^>^ MyRawdata = JsonConvert::DeserializeObject<System::Collections::Generic::IList<Topic_nfc^>^>(MyJson);
但是得到的,我想不出怎么才能访问Ndef
和tech
数据会员如。你能指出哪一个是IList的等价物吗?
谢谢
使用'List'而不是'IList',Json.NET不知道应该使用哪个具体类来反序列化到接口。 –
即使使用List来代替IList,我也不清楚哪一个是访问这些数据的代码。这将是'printf(“MyRawdata [i] - > id:%s \ n”,MyRawdata [i] - > id)的等价物;'为了获取tech1数据?这对我来说有点困惑。 – Fotakis
我不认为问题是'IList'。通过在Visual Studio中设置断点,我可以通过VS的用户界面评估'tech1'的值,并且这些值是正确的 - 因此可以使用'JsonConvert'很好地设置。问题是我如何引用MyRawdata结构来使用代码访问这些数据? – Fotakis