문제

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: []

    });
도움이 되었습니까?

해결책

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;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top