此代碼有什麼問題: 使用newton.jsoft(json.net)將c#翻譯爲vb.net時出錯。在Visual Studio 2012: 原始代碼:在Visual Studio 2012中使用newton.jsoft(json.net)將c#翻譯爲vb .net的翻譯錯誤
public static List<TradeInfo> GetTrades(BtcePair pair)
{
string queryStr = string.Format("https://btc-e.com/api/2/{0}/trades", BtcePairHelper.ToString(pair));
return JArray.Parse(WebApi.Query(queryStr)).OfType<JObject>().Select(TradeInfo.ReadFromJObject).ToList();
}
翻譯代碼:
Public Shared Function GetTrades(pair As BtcePair) As List(Of TradeInfo)
Dim queryStr As String = String.Format("https://btc-e.com/api/2/{0}/trades", _
BtcePairHelper.ToString(pair))
Return JArray.Parse(WebApi.Query(queryStr)).OfType(Of JObject)().[Select](TradeInfo.ReadFromJObject).ToList()
End Function
錯誤:
Error 1 Argument not specified for parameter 'o' of 'Public Shared Function ReadFromJObject(o As Newtonsoft.Json.Linq.JObject) As TradeInfo'.
調用的函數(VB):
Public Shared Function ReadFromJObject(o As JObject) As TradeInfo
If o Is Nothing Then
Return Nothing
End If
Return New TradeInfo() With
{.Amount = o.Value(Of Decimal)("amount"), _
.Price = o.Value(Of Decimal)("price"), _
.[Date] = UnixTime.ConvertToDateTime(o.Value(Of Long)("date")), _
.Item = BtceCurrencyHelper.FromString(o.Value(Of String)("item")), _
.PriceCurrency = BtceCurrencyHelper.FromString(o.Value(Of String)
("price_currency")), _
.Tid = o.Value(Of Long)("tid"), _
.Type = TradeInfoTypeHelper.FromString(o.Value(Of String)("trade_type")) _
}
End Function
IIRC,你需要'AddressOf'。 – SLaks
你的C#和VB版本根本不相似 - 你是以什麼方式將一個轉換爲另一個? –
使用在線工具在http://www.developerfusion.com/tools/convert/csharp-to-vb/ –