Java将JSONP返回的结果转化为对象

这里用了fastjson来解析json

package com.tntxia.geography.util;

import java.util.Map;

import com.alibaba.fastjson.JSON;

public class JSONPParser {
	
	public static Map parseJSONP(String jsonp){
		
		int startIndex = jsonp.indexOf("(");
		int endIndex = jsonp.lastIndexOf(")");
		String json = jsonp.substring(startIndex+1, endIndex);
		System.out.println(json);
		return JSON.parseObject(json);
	}
	
	public static void main(String[] args){
		
		Map map = parseJSONP("jsonp_test({})");
		
	}

}

猜你喜欢

转载自tntxia.iteye.com/blog/2367121