您的位置:首页 > 移动开发 > IOS开发

输出Bag中的所有记录为一个json数组---精通android、IOS App应用服务程序开发

2015-05-31 03:23 786 查看
书写闭合的json格式内容

{“item”:
{
<chtml>
… …
</chtml>
} ,"tatol":@{item:getLength}
}


与内层的标签运行结果共同组织一个完整的json格式文本输出到Android(IOS) App

"tatol":@{item:getLength}


为统计记录数

初始化Bag中的记录

同上一博

(您也可以从数据库中查询,如)

<esql module=help id=item>Select    ID,Subject,Writer,DayTime,Body  From        Messages</esql>


输出Bag中的所有记录

<for bags=item end="@{item:getLength}">
<item list="@{item:getSuffix}" end="@{item:getLength}">
<!-- list属性参数表示输出为数组列表格式,end属性参数表示数组结束的位置(跟for的end值相等) -->
<name>@{item:name}</name>
<price value>@{item:price}</price><!-- value属性参数表示输出不带引号的值 -->
<unit>@{item:unit}</unit>
</item>
</for>


list属性参数表示输出为数组列表格式,end属性参数表示数组结束的位置(跟for的end值相等)

结果

{"items":{
"item":[{"name":"土豆","price":1.24,"unit":"KG"},{"name":"T恤","price":68,"unit":"件"},{"name":"可乐","price":2.20,"unit":"瓶"},{"name":"书","price":51.24,"unit":"本"}]},"tatol":4
}


完整代码

{"items":{
<chtml>
<!-- 数据准备部分,您可以从数据库中查询 -->
<bag id=item suffix=0>
<we name=name>土豆</we>
<we name=price>1.24</we>
<we name=unit>KG</we>
</bag>
<bag id=item suffix=1>
<we name=name>T恤</we>
<we name=price>68</we>
<we name=unit>件</we>
</bag>
<bag id=item suffix=2>
<we name=name>可乐</we>
<we name=price>2.20</we>
<we name=unit>瓶</we>
</bag>
<bag id=item suffix=3>
<we name=name>书</we>
<we name=price>51.24</we>
<we name=unit>本</we>
</bag>
</chtml>
<chtml>
<!-- 正式json格式的内容 -->
<for bags=item end="@{item:getLength}"> <item list="@{item:getSuffix}" end="@{item:getLength}"> <!-- list属性参数表示输出为数组列表格式,end属性参数表示数组结束的位置(跟for的end值相等) --> <name>@{item:name}</name> <price value>@{item:price}</price><!-- value属性参数表示输出不带引号的值 --> <unit>@{item:unit}</unit> </item> </for>
</chtml>
},"tatol":@{item:getLength}
}


例子文件_samples/app/one_array.json在轻开平台的_samples/app/目录下

相关资源下载

移动App应用服务器开发从入门到精通:http://download.csdn.net/detail/tx18/8741611

快速搭建移动App服务器 :http://download.csdn.net/detail/tx18/8737507

轻开平台会不定期升级为大家提供更多强大而Easy的功能,请留意下载最新的版本:http://download.csdn.net/user/tx18
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android json ios app 应用