转换为字节数组后得到错误的颜色

时间:2018-08-22 02:54:13

标签: c#

将图像转换为字节数组后,我得到了奇怪的颜色。 它应该看起来像这样:

但是看起来像这样:

这是我的代码:

public class MyDeserializer
    implements JsonDeserializer<CountriesResponse> {
  @Override
  public CountriesResponse deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context)
      throws JsonParseException {
        final JsonArray jsonArray = json.getAsJsonArray();
        JsonObject rdObject =jsonArray get(0); //this is the ResponseDetails object
        CountriesResponse cr = new CountriesResponse();
        ///you might get this part for free with Retrofit since it is the top level object and JSON is expected as array of obj by default
        ////but if you did it manually it would look like:
        ResponseDetails rd = new ResponseDetails();
        //... now iterate the rdObject , setting the fields
         ...
        cr.setResponseDetails(rd);

        List cList = new ArrayList();
        JsonArray arr = jsonArray.get(1); //<-- this is your List<Country>
        //now you must iterate list and create a new Country for each one then add it to the List<Country> and set it on your CountriesResponse
        for (int i = 0; i < arr.length(); i++) {
           JSONObject jo = arr.getJSONObject(i);
           Country c = new Country();
           c.setName(jo.get("name");
           ...  set the capitalCity the same way
           cList.add();
        }
        cr.setCountriesList(cList)

       ...  
       return cr;
}

怎么了?

0 个答案:

没有答案