在尝试使用 Google Web Toolkit 的 JSNI 包装一些 Javascript API 时,我遇到了一个问题。javascript API 由基于云的服务器 Parse.com 提供。我的代码是这样的:
public class MMParseComm {
private MMProject project = new MMProject();//MMProject has a member: String projectName.
private String _projectName;
private native void _retrieveCurrentProject_step1(int projectId) /*-{
var ProjectList = $wnd.Parse.Object.extend("ProjectList");
var query = new $wnd.Parse.Query(ProjectList);
query.equalTo("projectId", projectId);
query.find({
success: function(results) {
//Questions here: In this function, I can access "_projectName" by
//this.@net.myname.myproject.myapi.client.MMParseComm::_projectName,
//but cannot access "project.projectName" using the same syntax.
//Also, I have searched around but cannot find a way
//that can write out a JSON data retrieved in "results"
//as a JSONObject in Java.
},
error: function(error) {
$wnd.alert("Error");
}
});
}-*/;
}
如上面的代码所示,问题在代码的注释部分。我不确定如何将数组results
中的字符串写入project.projectName
?另外,如何将results
在 javascript 中检索到的 JSON 数据包装为 Java 中的 JSONObject?
提前致谢!
卫斌