Search in sources :

Example 41 with JSONArray

use of com.alibaba.fastjson.JSONArray in project wechat-mp-sdk by usc.

the class MenuUtil method buildMenu.

private static Menu buildMenu(String json) {
    JSONObject parseObject = JSONObject.parseObject(json);
    if (json == null) {
        return null;
    }
    JSONObject menuObject = parseObject.getJSONObject("menu");
    if (menuObject == null) {
        return null;
    }
    JSONArray jsonArray = menuObject.getJSONArray("button");
    if (jsonArray == null) {
        return null;
    }
    List<MenuInfo> menuInfos = new ArrayList<MenuInfo>();
    for (int i = 0; i < jsonArray.size(); i++) {
        JSONObject subJsonObject = jsonArray.getJSONObject(i);
        String type = subJsonObject.getString("type");
        String jsonString = subJsonObject.toString();
        if (StringUtils.isNotEmpty(type)) {
            menuInfos.add(JSONObject.parseObject(jsonString, SingleMenuInfo.class));
        } else {
            menuInfos.add(JSONObject.parseObject(jsonString, MultiMenuInfo.class));
        }
    }
    return new Menu(menuInfos);
}
Also used : MultiMenuInfo(org.usc.wechat.mp.sdk.vo.menu.MultiMenuInfo) JSONObject(com.alibaba.fastjson.JSONObject) SingleMenuInfo(org.usc.wechat.mp.sdk.vo.menu.SingleMenuInfo) MultiMenuInfo(org.usc.wechat.mp.sdk.vo.menu.MultiMenuInfo) MenuInfo(org.usc.wechat.mp.sdk.vo.menu.MenuInfo) SingleMenuInfo(org.usc.wechat.mp.sdk.vo.menu.SingleMenuInfo) JSONArray(com.alibaba.fastjson.JSONArray) ArrayList(java.util.ArrayList) Menu(org.usc.wechat.mp.sdk.vo.menu.Menu)

Example 42 with JSONArray

use of com.alibaba.fastjson.JSONArray in project ready-x by CodePlayer.

the class User method parseArray.

@Test
public void parseArray() {
    JSONArray jsonArray = JSONUtil.parseArray("['大家好']");
    // 大家好
    System.out.println(jsonArray.get(0));
}
Also used : JSONArray(com.alibaba.fastjson.JSONArray) Test(org.junit.Test)

Example 43 with JSONArray

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

the class WXBridge method callNativeComponent.

/**
   * Bridge component Js Method
   * @param instanceId  Instance ID
   * @param componentRef  the ref of component
   * @param method  the name of method
   * @param arguments  the arguments of the method
   * @param options  option arguments for extending
   */
@Override
public void callNativeComponent(String instanceId, String componentRef, String method, byte[] arguments, byte[] options) {
    JSONArray argArray = JSON.parseArray(new String(arguments));
    WXBridgeManager.getInstance().callNativeComponent(instanceId, componentRef, method, argArray, options);
}
Also used : JSONArray(com.alibaba.fastjson.JSONArray)

Example 44 with JSONArray

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

the class WXDomModule method callDomMethod.

public void callDomMethod(JSONObject task) {
    if (task == null) {
        return;
    }
    String method = (String) task.get(WXBridgeManager.METHOD);
    JSONArray args = (JSONArray) task.get(WXBridgeManager.ARGS);
    callDomMethod(method, args);
}
Also used : JSONArray(com.alibaba.fastjson.JSONArray)

Example 45 with JSONArray

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

the class WXModuleManagerTest method testCallModuleMethod4.

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

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