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