Domanda

I am using extjs 3.4 .I have a from which contain along J SON value , i want to edit this value after that i want to validate the J SON .please tell me how can i do this. here is the code for the json edit from :

 var editJsonPanel = new Ext.form.FormPanel({

        id: "nosqlFP",
        baseCls: 'x-plain',
        labelWidth: 120,
        defaultType: 'textfield',
        monitorValid:true,
        bodyStyle: ' padding: 15px; background-color: #ffffff' ,
        items:[new Ext.form.TextArea({
            id:"editJsonDocumentId",
            fieldLabel: 'JsonDocument',
            allowBlank: false,
            name: 'jsonDocument',
            anchor: '90%',
            value: json
        })],
        listeners : {
            render : function(form){
            }
        },
        buttonAlign: 'center',
        buttons: []

    });
È stato utile?

Soluzione

Ext JS does not have any build in JSON validator. However if you just want to know if string is valid JSON or not you can use try/catch block and Ext.util.JSON.decode method.

function isValidJSON(str) {
    try {
        Ext.util.JSON.decode(str);
    } catch (e) {
        return false;
    }
    return true;
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top