use of com.alibaba.fastjson.JSONObject 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);
}
use of com.alibaba.fastjson.JSONObject in project uavstack by uavorg.
the class SMSAction method run.
@Override
public boolean run(NotificationEvent notifyEvent) {
// 模板关键字
Map<String, String> keywords = new HashMap<String, String>();
String title = notifyEvent.getTitle();
long timeFlag = notifyEvent.getTime();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String sd = sdf.format(new Date(timeFlag));
keywords.put("custName", sd);
keywords.put("comName", title);
/**
* 若notifyEvent中包含目的地址,则用该地址;否则使用默认地址
*/
String sms = notifyEvent.getArg(cName);
if (StringHelper.isEmpty(sms)) {
if (log.isTraceEnable()) {
log.warn(this, "Send SMS FAIL as no any phone numbers.");
}
return false;
}
String[] phoneNums = sms.split(",");
for (String phone : phoneNums) {
List<ParaValuePair> nvps = new ArrayList<ParaValuePair>();
// 接口版本
nvps.add(new ParaValuePair("version", "3.0"));
// 批次号
nvps.add(new ParaValuePair("batchId", Long.toString(System.currentTimeMillis())));
// 组织机构号
nvps.add(new ParaValuePair("orgNo", "2265"));
// 模板号
nvps.add(new ParaValuePair("typeNo", "7209"));
// 关键字替换
nvps.add(new ParaValuePair("keywords", JSON.toJSONString(keywords)));
// 手机号
nvps.add(new ParaValuePair("mobile", phone));
if (log.isDebugEnable()) {
log.debug(this, "Send SMS START: phone=" + phone);
}
final String phoneNum = phone;
client.doAsyncHttpPost(baseUrl + "send", nvps, "utf-8", new HttpClientCallback() {
@Override
public void completed(HttpClientCallbackResult result) {
String results = result.getReplyDataAsString();
JSONObject jo = JSON.parseObject(results);
// 错误码
String code = jo.getString("code");
// 错误信息
String desc = jo.getString("desc");
if (log.isDebugEnable()) {
log.debug(this, "Send SMS END: phone=" + phoneNum + ",code=" + code + ",desc=" + desc);
}
}
@Override
public void failed(HttpClientCallbackResult result) {
String results = result.getReplyDataAsString();
log.err(this, "Send SMS FAIL: phone=" + phoneNum + ", result=" + results);
}
});
}
return true;
}
use of com.alibaba.fastjson.JSONObject in project uavstack by uavorg.
the class TaildirLogComponent method writePosition.
private void writePosition(boolean isAppend) {
File file = new File(positionFilePath);
LineNumberReader reader = null;
FileWriter writer = null;
@SuppressWarnings("rawtypes") List<Map> json = Lists.newArrayList();
if (!existingInodes.isEmpty()) {
json.addAll(toPosInfoJson());
}
try {
reader = new LineNumberReader(new FileReader(file));
JSONArray array = Optional.fromNullable(JSONObject.parseArray(reader.readLine())).or(new JSONArray());
for (int i = 0; i < array.size(); i++) {
JSONObject posfile = array.getJSONObject(i);
if (!existingInodes.contains(posfile.getLongValue("inode")))
json.add(ImmutableMap.of("inode", posfile.getLongValue("inode"), "pos", posfile.getLongValue("pos"), "num", posfile.getLong("num"), "file", posfile.getString("file")));
}
writer = new FileWriter(file);
writer.write(JSONObject.toJSONString(json));
} catch (Throwable t) {
log.err(this, "Failed writing positionFile", t);
} finally {
try {
if (reader != null)
reader.close();
} catch (IOException e) {
log.err(this, "Error: " + e.getMessage(), e);
}
try {
if (writer != null)
writer.close();
} catch (IOException e) {
log.err(this, "Error: " + e.getMessage(), e);
}
}
}
use of com.alibaba.fastjson.JSONObject in project uavstack by uavorg.
the class DefaultJSONParser method parseArray.
@SuppressWarnings({ "unchecked", "rawtypes" })
public final void parseArray(final Collection array, Object fieldName) {
final JSONLexer lexer = getLexer();
if (lexer.token() == JSONToken.SET || lexer.token() == JSONToken.TREE_SET) {
lexer.nextToken();
}
if (lexer.token() != JSONToken.LBRACKET) {
throw new JSONException("syntax error, expect [, actual " + JSONToken.name(lexer.token()) + ", pos " + lexer.pos());
}
lexer.nextToken(JSONToken.LITERAL_STRING);
ParseContext context = this.getContext();
this.setContext(array, fieldName);
try {
for (int i = 0; ; ++i) {
if (isEnabled(Feature.AllowArbitraryCommas)) {
while (lexer.token() == JSONToken.COMMA) {
lexer.nextToken();
continue;
}
}
Object value;
switch(lexer.token()) {
case LITERAL_INT:
value = lexer.integerValue();
lexer.nextToken(JSONToken.COMMA);
break;
case LITERAL_FLOAT:
if (lexer.isEnabled(Feature.UseBigDecimal)) {
value = lexer.decimalValue(true);
} else {
value = lexer.decimalValue(false);
}
lexer.nextToken(JSONToken.COMMA);
break;
case LITERAL_STRING:
String stringLiteral = lexer.stringVal();
lexer.nextToken(JSONToken.COMMA);
if (lexer.isEnabled(Feature.AllowISO8601DateFormat)) {
JSONScanner iso8601Lexer = new JSONScanner(stringLiteral);
if (iso8601Lexer.scanISO8601DateIfMatch()) {
value = iso8601Lexer.getCalendar().getTime();
} else {
value = stringLiteral;
}
iso8601Lexer.close();
} else {
value = stringLiteral;
}
break;
case TRUE:
value = Boolean.TRUE;
lexer.nextToken(JSONToken.COMMA);
break;
case FALSE:
value = Boolean.FALSE;
lexer.nextToken(JSONToken.COMMA);
break;
case LBRACE:
JSONObject object = new JSONObject(isEnabled(Feature.OrderedField));
value = parseObject(object, i);
break;
case LBRACKET:
Collection items = new JSONArray();
parseArray(items, i);
value = items;
break;
case NULL:
value = null;
lexer.nextToken(JSONToken.LITERAL_STRING);
break;
case UNDEFINED:
value = null;
lexer.nextToken(JSONToken.LITERAL_STRING);
break;
case RBRACKET:
lexer.nextToken(JSONToken.COMMA);
return;
case EOF:
throw new JSONException("unclosed jsonArray");
default:
value = parse();
break;
}
array.add(value);
checkListResolve(array);
if (lexer.token() == JSONToken.COMMA) {
lexer.nextToken(JSONToken.LITERAL_STRING);
continue;
}
}
} finally {
this.setContext(context);
}
}
use of com.alibaba.fastjson.JSONObject in project uavstack by uavorg.
the class DefaultJSONParser method parseObject.
public JSONObject parseObject() {
JSONObject object = new JSONObject(isEnabled(Feature.OrderedField));
parseObject(object);
return object;
}
Aggregations