我一直在試圖將這個語句從C#轉換爲JAVA,沒有太多的運氣。是的,我搜索了Azure,stackoverflow等等,但在java中找不到READDOCUMENT的一個好例子。C#轉Java使用相同的Azure SDK,只是不同的語言
UserInfo response = _DocumentClient.ReadDocument<UserInfo>(UriFactory.CreateDocumentUri(_DBConfiguration.DatabaseID, _DBConfiguration.DocumentCollectionId, pPhoneNumber));
這是據我已經得到了:
UserInfo returnUserInfo = null;
try {
//todo: document link is incorrect, but reference pPhoneNumber as key
ResourceResponse<Document> response = _DocumentClient.readDocument(<<NEED To generate URI>>,null);
if (response != null) {
Document returnUserInfoDocument = response.getResource();
returnUserInfo = <<I have a document, but can't cast it to USERINFO>>;
}
}
catch (DocumentClientException ex) {
if (!ex.getError().getCode().equals("NotFound")) {
throw ex;
}
}
return returnUserInfo;
Tks-你在SDK之間爲我引發了一個不同的視角。 stackoverflow有很多「代碼爲我的問題」,但我的搜索上下文非常不同 - 我使用「Azure JAVA sdk ReadDocument」 - 它返回了一個不同的結果集。我應該像你一樣使用更一般的搜索,但是,您提供的鏈接顯示了一種技術來確定文檔是否存在,並通過異常進行管理。它對返回值沒有任何作用,這可能是我解僱它的原因。不過,你也幫助過JSON,讓我走上正軌。謝謝您的幫助! – codeputer