forked from docs/doc-exports
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com> Co-authored-by: chenxiaoxiong <chenxiaoxiong@huawei.com> Co-committed-by: chenxiaoxiong <chenxiaoxiong@huawei.com>
82 lines
5.7 KiB
HTML
82 lines
5.7 KiB
HTML
<a name="dataartsstudio_01_0501"></a><a name="dataartsstudio_01_0501"></a>
|
|
|
|
<h1 class="topictitle1">JSONUtil Embedded Objects</h1>
|
|
<div id="body8662426"><p id="dataartsstudio_01_0501__en-us_topic_0132846500_p6373151120335">A JSONUtil embedded object provides JSON object methods.</p>
|
|
<div class="section" id="dataartsstudio_01_0501__en-us_topic_0132846500_section18267348332"><h4 class="sectiontitle">Methods</h4>
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="dataartsstudio_01_0501__en-us_topic_0132846500_table874717402336" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Method description</caption><thead align="left"><tr id="dataartsstudio_01_0501__en-us_topic_0132846500_row167470408331"><th align="left" class="cellrowborder" valign="top" width="28.660000000000004%" id="mcps1.3.2.2.2.4.1.1"><p id="dataartsstudio_01_0501__en-us_topic_0132846500_p1774714014337">Method</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="36.28%" id="mcps1.3.2.2.2.4.1.2"><p id="dataartsstudio_01_0501__en-us_topic_0132846500_p177471640193311">Description</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="35.06%" id="mcps1.3.2.2.2.4.1.3"><p id="dataartsstudio_01_0501__p699944151217">Example</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="dataartsstudio_01_0501__en-us_topic_0132846500_row1747740123312"><td class="cellrowborder" valign="top" width="28.660000000000004%" headers="mcps1.3.2.2.2.4.1.1 "><p id="dataartsstudio_01_0501__en-us_topic_0132846500_p127471840153312">Object parse(String jsonStr)</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="36.28%" headers="mcps1.3.2.2.2.4.1.2 "><p id="dataartsstudio_01_0501__en-us_topic_0132846500_p1874724010332">Converts a JSON character string into an object.</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="35.06%" headers="mcps1.3.2.2.2.4.1.3 "><p id="dataartsstudio_01_0501__p3999164151216">Assume that variable a is a JSON string. Use the following EL expression to convert the JSON string into an object:</p>
|
|
<p id="dataartsstudio_01_0501__p152176248383">#{JSONUtil.parse(a)}</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dataartsstudio_01_0501__en-us_topic_0132846500_row3747154018335"><td class="cellrowborder" valign="top" width="28.660000000000004%" headers="mcps1.3.2.2.2.4.1.1 "><p id="dataartsstudio_01_0501__en-us_topic_0132846500_p11747184043316">String toString(Object jsonObject)</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="36.28%" headers="mcps1.3.2.2.2.4.1.2 "><p id="dataartsstudio_01_0501__en-us_topic_0132846500_p17747184016331">Converts an object to a JSON character string.</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="35.06%" headers="mcps1.3.2.2.2.4.1.3 "><p id="dataartsstudio_01_0501__p1485413918327">Assume that variable b is an object. Use the following EL expression to convert the object into a JSON string:</p>
|
|
<p id="dataartsstudio_01_0501__p1854129143215">#{JSONUtil.toString(b)}</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dataartsstudio_01_0501__en-us_topic_0132846500_row197471240123319"><td class="cellrowborder" valign="top" width="28.660000000000004%" headers="mcps1.3.2.2.2.4.1.1 "><p id="dataartsstudio_01_0501__en-us_topic_0132846500_p1974794003313">Object path(String jsonStr,String jsonPath)</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="36.28%" headers="mcps1.3.2.2.2.4.1.2 "><p id="dataartsstudio_01_0501__en-us_topic_0132846500_p107471840133310">Returns the field value in a path specified by the JSON character string. This method is similar to XPath and can be used to retrieve or set JSON by path. You can use . or [] in the path to access members and values. For example, tables[0].table_name.</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="35.06%" headers="mcps1.3.2.2.2.4.1.3 "><div class="p" id="dataartsstudio_01_0501__p14391101223314">The content of variable str is as follows:<pre class="screen" id="dataartsstudio_01_0501__screen17391191243310">{
|
|
"cities": [{
|
|
"name": "city1",
|
|
"areaCode": "1000"
|
|
},
|
|
{
|
|
"name": "city2",
|
|
"areaCode": "2000"
|
|
},
|
|
{
|
|
"name": "city3",
|
|
"areaCode": "3000"
|
|
}]
|
|
}</pre>
|
|
</div>
|
|
<div class="p" id="dataartsstudio_01_0501__p4392612173315">The expression for obtaining the area code of city1 is as follows:<pre class="screen" id="dataartsstudio_01_0501__screen839291211331">#{JSONUtil.path(str,"cities[0].areaCode")}</pre>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="dataartsstudio_01_0501__en-us_topic_0132846500_section115011297442"><h4 class="sectiontitle"><strong id="dataartsstudio_01_0501__en-us_topic_0132846500_b20439956184315">Example</strong></h4><p id="dataartsstudio_01_0501__en-us_topic_0132846500_p1726613116446">The content of variable str is as follows:</p>
|
|
<pre class="screen" id="dataartsstudio_01_0501__en-us_topic_0132846500_screen45391926194418">{
|
|
"cities": [{
|
|
"name": "city1",
|
|
"areaCode": "1000"
|
|
},
|
|
{
|
|
"name": "city2",
|
|
"areaCode": "2000"
|
|
},
|
|
{
|
|
"name": "city3",
|
|
"areaCode": "3000"
|
|
}]
|
|
}</pre>
|
|
</div>
|
|
<p id="dataartsstudio_01_0501__en-us_topic_0132846500_p2446164784417">The expression for obtaining the area code of city1 is as follows:</p>
|
|
<pre class="screen" id="dataartsstudio_01_0501__en-us_topic_0132846500_screen67421223154516">#{JSONUtil.path(str,"cities[0].areaCode")}</pre>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="dataartsstudio_01_0493.html">EL Expression Reference</a></div>
|
|
</div>
|
|
</div>
|
|
|