JxBrowser JavaScript Java Bridge API allows passing a string that represents JSON from Java side to JavaScript. On JavaScript side this JSON string will be parsed and converted to appropriate JavaScript object/objects. The following simple example demonstrates how to associate JSON with specific property of window JavaScript object:  (JxBrowser JavaScript Java Bridge API允许将表示JSON的字符串从Java端传递到JavaScript。在JavaScript方面,此JSON字符串将被解析并转换为适当的JavaScript对象。以下简单示例演示如何将JSON与窗口JavaScript对象的特定属性相关联:)

JSValue window = browser.executeJavaScriptAndReturnValue("window");
window.asObject().setProperty("myObject", new JSONString("[123, \"Hello\"]"));

In the code above the "[123, \"Hello\"]" JSON string is associated with the window.myObject property. This JSON string will be converted to appropriate JavaScript object. In this case it will be converted to Array. The following JavaScript code shows how to work with the window.myObject property:(在“ [123,\” Hello \“]” JSON字符串上方的代码中,window.myObject属性与JSON字符串相关联。此JSON字符串将转换为适当的JavaScript对象。在这种情况下,它将转换为数组。以下JavaScript代码显示了如何使用window.myObject属性:)

<script>
var length = window.myObject.length;
var numberValue = window.myObject[0];
var stringValue = window.myObject[1];
</script>

If you set JSONString with string value that doesn't represent JSON, you will get JavaScript error.(如果将JSONString设置为非JSON字符串值,则会出现JavaScript错误。)