最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - JavascriptObject to string gwt - Stack Overflow

programmeradmin7浏览0评论

I have bee a great fan of the JavaScriptOverlayTypes.

so lets say, I have the followin JSON object:

 {
  "product": {
    "name": "Widget",
    "prices": 
      { "minQty": 1, "price": 12.49 }
  }
}

So I write my class for products and one for prices. Now if somethings wents wrong when analysing the "price JavascriptObject", I want to print it as the following:

{ "minQty": 1, "price": 12.49 }

but I havent found a possibilty yet to confert the "price JavascriptObject" backt to a string.

Is there a possibilty to do this?

Regards, Stefan

I have bee a great fan of the JavaScriptOverlayTypes.

so lets say, I have the followin JSON object:

 {
  "product": {
    "name": "Widget",
    "prices": 
      { "minQty": 1, "price": 12.49 }
  }
}

So I write my class for products and one for prices. Now if somethings wents wrong when analysing the "price JavascriptObject", I want to print it as the following:

{ "minQty": 1, "price": 12.49 }

but I havent found a possibilty yet to confert the "price JavascriptObject" backt to a string.

Is there a possibilty to do this?

Regards, Stefan

Share Improve this question asked Sep 23, 2011 at 11:42 StefanStefan 15k17 gold badges92 silver badges153 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

new JSONObject(priceJso).toString()

Beware of performance thugh, as it'll create a JSONValue object for each property of the object (and recursively of course), and I'm not sure the GWT piler is able to optimize things much.
In your case, as an "error path", it should be OK though.

JsonUtils has a nice function for it:

String jsonString = JsonUtils.stringify(priceJson);

Which has the native implementation:

public static native String stringify(JavaScriptObject obj) /*-{ JSON.stringify(obj); }-*/;
发布评论

评论列表(0)

  1. 暂无评论