Search in sources :

Example 46 with JSONArray

use of com.alibaba.fastjson.JSONArray in project weex-example by KalicyZhou.

the class WXModuleManagerTest method testCallModuleMethod3.

@Test
public void testCallModuleMethod3() throws Exception {
    JSONArray args = new JSONArray();
    args.add("testarg");
    args.add(null);
    WXModuleManager.callModuleMethod(instance.getInstanceId(), "test1", "testCallbackMethod", args);
}
Also used : JSONArray(com.alibaba.fastjson.JSONArray) Test(org.junit.Test) WXSDKInstanceTest(com.taobao.weex.WXSDKInstanceTest)

Example 47 with JSONArray

use of com.alibaba.fastjson.JSONArray in project weex-example by KalicyZhou.

the class WXDomModuleTest method testCallDomMethod.

@Test
public void testCallDomMethod() throws Exception {
    module.callDomMethod(null);
    JSONObject obj = new JSONObject();
    for (String m : METHODS) {
        obj.put(WXBridgeManager.METHOD, m);
        module.callDomMethod(obj);
    }
    obj = new JSONObject();
    for (Object[] args : ARGS_CASES) {
        JSONArray ary = new JSONArray();
        if (args == null) {
            ary = null;
        } else {
            for (Object arg : args) {
                ary.add(arg);
            }
        }
        obj.put(WXBridgeManager.ARGS, ary);
        for (String m : METHODS) {
            obj.put(WXBridgeManager.METHOD, m);
            module.callDomMethod(obj);
        }
    }
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONArray(com.alibaba.fastjson.JSONArray) JSONObject(com.alibaba.fastjson.JSONObject) Test(org.junit.Test) WXSDKInstanceTest(com.taobao.weex.WXSDKInstanceTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 48 with JSONArray

use of com.alibaba.fastjson.JSONArray in project weex-example by KalicyZhou.

the class WXDomObjectTest method testClone.

@Test
public void testClone() throws Exception {
    JSONObject.parseObject("{\"ref\":\"100\",\"type\":\"div\",\"attr\":{},\"style\":{\"backgroundColor\":\"rgb(40,96,144)\",\"fontSize\":40,\"color\":\"#ffffff\",\"paddingRight\":30,\"paddingLeft\":30,\"paddingBottom\":20,\"paddingTop\":20}}");
    JSONObject obj = new JSONObject();
    obj.put("ref", "101");
    obj.put("type", "test");
    JSONArray event = new JSONArray();
    event.add("click");
    obj.put("event", event);
    dom.parseFromJson(obj);
    WXDomObject clone = dom.clone();
    assertEquals(clone.getRef(), "101");
    assertEquals(clone.getType(), "test");
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONArray(com.alibaba.fastjson.JSONArray) Test(org.junit.Test)

Example 49 with JSONArray

use of com.alibaba.fastjson.JSONArray in project api-manager by cehome-com.

the class AmActionServiceImpl method buildMockData.

private JSONObject buildMockData(List<JSONObject> columnList) {
    JSONObject mockObject = new JSONObject();
    for (JSONObject column : columnList) {
        int columnType = column.getIntValue("type");
        if (CommonMeta.JavaType.NUMBER.getCode() == columnType || CommonMeta.JavaType.STRING.getCode() == columnType || CommonMeta.JavaType.BOOLEAN.getCode() == columnType || CommonMeta.JavaType.ARRAY_NUMBER.getCode() == columnType || CommonMeta.JavaType.ARRAY_STRING.getCode() == columnType || CommonMeta.JavaType.ARRAY_BOOLEAN.getCode() == columnType) {
            String name = column.getString("name");
            String rule = StringUtils.isEmpty(column.getString("rule")) ? "" : "|" + column.getString("rule");
            Object value = column.get("value");
            mockObject.put(name + rule, value);
        } else if (CommonMeta.JavaType.OBJECT.getCode() == columnType) {
            String name = column.getString("name");
            List<JSONObject> children = column.getJSONArray("child").toJavaList(JSONObject.class);
            JSONObject columnObject = buildMockData(children);
            mockObject.put(name, columnObject);
        } else if (CommonMeta.JavaType.ARRAY_OBJECT.getCode() == columnType) {
            JSONArray objectArray = new JSONArray();
            String name = column.getString("name");
            List<JSONObject> children = column.getJSONArray("child").toJavaList(JSONObject.class);
            for (JSONObject child : children) {
                List<JSONObject> innerChildren = child.getJSONArray("child").toJavaList(JSONObject.class);
                JSONObject innerColumnObject = buildMockData(innerChildren);
                objectArray.add(innerColumnObject);
            }
            mockObject.put(name, objectArray);
        }
    }
    return mockObject;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONArray(com.alibaba.fastjson.JSONArray) JSONObject(com.alibaba.fastjson.JSONObject) List(java.util.List)

Example 50 with JSONArray

use of com.alibaba.fastjson.JSONArray in project CorePage by lizhangqu.

the class CorePageManager method readConfig.

/**
 * 从配置文件中读取page
 */
public void readConfig(String content) {
    Log.d(TAG, "readConfig from json");
    JSONArray jsonArray = JSON.parseArray(content);
    Iterator<Object> iterator = jsonArray.iterator();
    JSONObject jsonPage = null;
    String pageName = null;
    String pageClazz = null;
    String pageParams = null;
    while (iterator.hasNext()) {
        jsonPage = (JSONObject) iterator.next();
        pageName = jsonPage.getString("name");
        pageClazz = jsonPage.getString("class");
        pageParams = jsonPage.getString("params");
        if (TextUtils.isEmpty(pageName) || TextUtils.isEmpty(pageClazz)) {
            Log.d(TAG, "page Name is null or pageClass is null");
            return;
        }
        mPageMap.put(pageName, new CorePage(pageName, pageClazz, pageParams));
        Log.d(TAG, "put a page:" + pageName);
    }
    Log.d(TAG, "finished read pages,page size:" + mPageMap.size());
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONArray(com.alibaba.fastjson.JSONArray) JSONObject(com.alibaba.fastjson.JSONObject)

Aggregations

JSONArray (com.alibaba.fastjson.JSONArray)95 JSONObject (com.alibaba.fastjson.JSONObject)39 ArrayList (java.util.ArrayList)13 List (java.util.List)9 Test (org.junit.Test)8 StringReader (java.io.StringReader)6 DefaultJSONParser (com.alibaba.fastjson.parser.DefaultJSONParser)5 JSONReaderScanner (com.alibaba.fastjson.parser.JSONReaderScanner)5 Reader (java.io.Reader)5 WXSDKInstanceTest (com.taobao.weex.WXSDKInstanceTest)4 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 Test (org.testng.annotations.Test)4 BigDecimal (java.math.BigDecimal)3 ParseException (java.text.ParseException)3 Map (java.util.Map)3 Setting (org.aisen.android.common.setting.Setting)3 JSONReader (com.alibaba.fastjson.JSONReader)2 InputStream (java.io.InputStream)2 ParameterizedType (java.lang.reflect.ParameterizedType)2