在做一个接口的时候,请求格式是这样的:
{
"items":
[
{"val":"0.000","result":1,"name":"ID"},
{"val":"000000000000000003","result":1,"name":"SerialNum"},
{"val":"8.772","result":1,"name":"Isc"},
{"val":"6.787","result":1,"name":"Voc"},
{"val":"8.042","result":1,"name":"Ipm"},
{"val":"4.755","result":1,"name":"Vpm"},{"val":"2.778","result":1,"name":"CellEfficiency"},{"val":"64.233","result":1,"name":"FF"},{"val":"23","result":1,"name":"Grade"},{"val":"96.416","result":1,"name":"Temp"},{"val":"93.028","result":1,"name":"Irradiance"},{"val":"0.102","result":1,"name":"Rs"},{"val":"0.000","result":1,"name":"Rsh"},{"val":"0.000","result":1,"name":"CellArea"}]}
items 进行json反序列化后是个数组,我需要把数组的内容进行存储数据库,我本来是这样写的:
但是这样写的话,如果我有一条数据是没有的,传过来的数组长度与设置的不一致,就会报错了,有什么好的处理方式吗?谢谢!
|