我有以下JSON:返回JSON沒有XML
{ "Test": {"Header": {"Description": "OK", "Status": "000", "Timestamp": "1338805752" }, "Results": {"Sport": {"Country": { "League": [ {"Name": "ECB 40 League", "TargetURL": "\/Cricket\/International\/ECB 40 League", "Total": "5" }, {"Name": "Friends Life T20 2012", "TargetURL": "\/Cricket\/International\/Friends Life T20 2012", "Total": "0" }, {"Name": "Sri Lanka vs Pakistan (ODI Series)", "TargetURL": "\/Cricket\/International\/Sri Lanka vs Pakistan (ODI Series)", "Total": "0" }, {"Name": "Sri Lanka vs Pakistan 1st ODI", "TargetURL": "\/Cricket\/International\/Sri Lanka vs Pakistan 1st ODI", "Total": "1" }, {"Name": "Test Series", "TargetURL": "\/Cricket\/International\/Test Series", "Total": "1" } ], "Name": "International", "TargetURL": "\/Cricket\/International", "Total": "6" }, "Name": "Cricket", "Total": "5" } } }}
當我從我的C#代碼返回它,我得到這樣說:
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">{ "HotOdds": {"Header": {"Description": "OK", "Status": "000", "Timestamp": "1338805752" }, "Results": {"Sport": {"Country": { "League": [ {"Name": "ECB 40 League", "TargetURL": "\/Cricket\/International\/ECB 40 League", "Total": "5" }, {"Name": "Friends Life T20 2012", "TargetURL": "\/Cricket\/International\/Friends Life T20 2012", "Total": "0" }, {"Name": "Sri Lanka vs Pakistan (ODI Series)", "TargetURL": "\/Cricket\/International\/Sri Lanka vs Pakistan (ODI Series)", "Total": "0" }, {"Name": "Sri Lanka vs Pakistan 1st ODI", "TargetURL": "\/Cricket\/International\/Sri Lanka vs Pakistan 1st ODI", "Total": "1" }, {"Name": "Test Series", "TargetURL": "\/Cricket\/International\/Test Series", "Total": "1" } ], "Name": "International", "TargetURL": "\/Cricket\/International", "Total": "6" }, "Name": "Cricket", "Total": "5" } } }}</string>
下面是函數的定義:
[OperationContract(Name = "GetHOSports")]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
string GetSportsList(DateTime date, int sportID);
我不明白爲什麼我得到XML元素內的JSON,任何人?
是的,我得到相同的輸出。 –
@IdoLazar查看我更新的答案。你是否創建了C#類來生成你想要的JSON。 –