Rhino: return JSON from within Java

后端 未结 3 1943
青春惊慌失措
青春惊慌失措 2021-01-22 08:51

I have the string representation of a JSON-serialized object in Java e.g. \"{\\\"name\\\":\\\"John\\\",\\\"age\\\":24}\". How do I parse and return it to the JavaSc

3条回答
  •  遇见更好的自我
    2021-01-22 09:42

    Another way to do it is by calling org.mozilla.javascript.json.JsonParser.parseValue. That is if you don't need to apply a reviver.

    More interestingly, org.mozilla.javascript.NativeJSON is built around org.mozilla.javascript.json.JsonParser.parseValue. And you can see that here, https://github.com/mozilla/rhino/blob/master/src/org/mozilla/javascript/NativeJSON.java#L110.

提交回复
热议问题