`
tntxia
  • 浏览: 1486843 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

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({})");
		
	}

}

 

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics