建行手机银行转账时出现object key string expected string at

android报错 Expected BEGIN_OBJECT but was STRING at line 1 column 39 path $
博客专家
android报错 Expected BEGIN_OBJECT but was STRING at line 1 column 39 path $
android项目
& & & 我在使用retrofit和Gson配合时,出现了这个问题,疑惑中乱七八糟瞎搞了一个下午没有解决。期间怀疑Gson解析不能使用泛型(因为我的解析使用了泛型),后来又觉得可能是我的关键字正好是解析器的某个关键字导致的异常,也打算过自定义Gson的解析过程,其实这些都不是。& & & & 第二天才搞明白,真正的问题是我的数据结构有问题,或者说我的解析出现了问题。& & & & 例如下面Json字符串:& & & &&{&code&:1,&info&:&success&,&results&:{&id&:&1&,&name&:&hehe&}}& & & & results对应的应该是一个实体类,如果这个时候想把他解析为String或者List就会出现异常。& & & & 如果参考使用GsonForm处理后的数据模型,几乎不会出现问题;加入result后面的内容可能在请求时会因为某些原因会存在格式上的变化,这个时候就有出现该异常的风险。Gson中,关键字后面出现&&引起来的内容将会被只认为是STRING,“{}”只被认为是类,“[]”只被认为是List,这个几乎是强制性的。& & & & 就是说如果你的实体预计是获取String的变量,但是关键字后面对应的却出现了“{”或“[”,那么这个转换将被认为是错误的,抛出异常。& & & & 解决办法:后台输出稳定的Gson格式。
我的热门文章
即使是一小步也想与你分享android - java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 62 - Stack Overflow
Join the Stack Overflow Community
Stack Overflow is a community of 7.1 million programmers, just like you, helping each other.
J it only takes a minute:
I am facing a problem about the GSON json to Java. I looked up many posts here, but I cannot find the solution for my question. So I list my problem here.I am trying to get the data there is a Map in json but I am not able to retrieve the data . In my log I am able to see that only this much data is coming then it throws the exception . Someone please guide me a way through. Thanks very much !
Here is my Json Data on hitting the URL from the Android app i am working on
"success" : true,
"messages" : {
"success" : [
"SEARCH_QUERY_SUCCESS"
"session" : {
"id" : "cn694ivr8bmqnrveh9n8841oh7",
"expire" : "",
"YII_CSRF_TOKEN" : "4fa0ae103b050919"
"metadata" : {
"product_count" : "4458",
"category_ids" : "3",
"results" : [{
"id" : "105089",
"data" : {
"sku" : "MA851AA10ZLX",
"name" : "Alexa Mid Rise Super Skinny Leg",
"new-product" : false,
"url" : "http:\/\/theiconic.bugfoot.de\/mobile-api\/Alexa-Mid-Rise-Super-Skinny-Leg-105089.html",
"simples" : {
"MA851AA10ZLX-406437" : {},
"MA851AA10ZLX-406438" : {},
"MA851AA10ZLX-406439" : {},
"MA851AA10ZLX-406440" : {},
"MA851AA10ZLX-406441" : {},
"MA851AA10ZLX-406442" : {},
"MA851AA10ZLX-406443" : {},
"MA851AA10ZLX-406444" : {
"meta" : {
"sku" : "MA851AA10ZLX-406444",
"price" : "149.99",
"caching_hash" : "78ddaaf930f8bd0e0bf595cd",
"shipment_cost_item" : "0.00",
"shipment_cost_order" : "0.00",
"tax_percent" : "10.00",
"quantity" : "2",
"cost" : "64.09",
"size_brand" : "W31\/L34",
"size" : "W31\/L34",
"size_position" : "200",
"3hours_shipment_available" : true,
"estimated_delivery" : "",
"estimated_delivery_position" : ""
"attributes" : {
"sort_order" : "0",
"size" : "W31\/L34"
This is my network class used for parsing
String jsonString =
HttpGet httppost = new HttpGet(URL);
HttpClient httpClient = new DefaultHttpClient();
if (httpClient != null) {
HttpResponse response = httpClient.execute(httppost);
BufferedReader reader = new BufferedReader(
new InputStreamReader(
response.getEntity().getContent(), "UTF-8"));
jsonString = reader.readLine();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println(jsonString);
if (jsonString != null) {
Bean obj=new Gson().fromJson(jsonString, Bean.class);
Message msg = new Message();
responseHandler.sendMessage(msg);
//obj can be sent to a handler
This is Simples Bean class containing a Map
public class Simples {
private Map&String, KeyMap& keyM
public Map&String, KeyMap& getKeyMap() {return keyM}
public void setKeyMap(Map&String, KeyMap& keyMap) {this.keyMap = keyM}}
This is my KeyMap Bean class
public class KeyMap {
public Meta getMeta() {
public void setMeta(Meta meta) {
this.meta =
public Attributes getAttributes() {
public void setAttributes(Attributes attributes) {
this.attributes =
2,53711519
Actually your were getting error BEGIN_OBJECT but was STRING because gson was expecting object not the string, also it is an object in json, you have wrong mapped your classes in
Bean class, and you have not posted the Bean,Simple class glue code here.
You JSON model classes can be mapped as like this
public class ProductInfo {
private Map&String, String[]&
private SessionD
private MetaD
public class SessionData {
private String YII_CSRF_TOKEN;
public class MetaData {
private String product_
private String category_
private List&Result&
public class Result {
public class Data {
@SerializedName(value = "new-product")
private String newP
Map&String, KeyMap&
public class KeyMap {
public class Meta {
private S;
private String caching_
private String shipment_cost_
private String shipment_cost_
private String tax_
private String size_
private String size_
@SerializedName(value = "3hours_shipment_available")
private String hours_shipment_
private String estimated_
private String estimated_delivery_
public class Attributes {
private String sort_
Finally de-serialize it
ProductInfo productInfo = gson.fromJson(reader, ProductInfo.class);
2,53711519
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
rev .25896
Stack Overflow works best with JavaScript enabled}

我要回帖

更多关于 expected string at 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信