---
title: "Handling JSON NULL"
author: "tanbamboo"
date: "2009-08-05T17:13:51Z"
tags: ["EXT", "Java", "PHP", "json"]
slug: "handling-json-null"
draft: false
lastmod: "2009-08-05T17:13:51Z"
id: 440867
url: "https://tanbamboo.iteye.com/blog/440867"
---

原文：<http://extjs.com/forum/showthread.php?t=46336>

通过为Ext.data.JsonReader的字段加上convert来处理条件映射的问题。

示例如下：

```java
{"licences":[{"id":2,"licensekey":"123456","point":null,"owner":{"id":1,"name":"witbit"}, "mac":null,"active":false},

{"id":3,"licensekey":"789013","point":null,"owner":null, "mac":null,"active":false}]} 
```



```java
this.DS  = new Ext.data.Store(

{

    reader: new Ext.data.JsonReader(

            { 

                root: "licences",

                fields: [ "id", "licensekey", {name:"owner_name", mapping:"owner.name"}, "point",  "mac", "active" ] 

            })

}); 
```


修改Owerne.Name的Mapping方式为下面：

```java
{name:"Owner_Name", mapping:"Owner", convert: function(v) {return v ? v.Name : null;}}
```