JsonUtils.java 4.41 KB
package com.arellomobile.android.push.utils;

import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class JsonUtils
{
  private static Object a(Object paramObject)
  {
    Object localObject;
    if (paramObject == null) {
      localObject = null;
    }
    for (;;)
    {
      return localObject;
      localObject = paramObject;
      if (!(paramObject instanceof JSONArray))
      {
        localObject = paramObject;
        if (!(paramObject instanceof JSONObject)) {
          try
          {
            if ((paramObject instanceof Collection)) {
              return collectionToJson((Collection)paramObject);
            }
            if (paramObject.getClass().isArray()) {
              return arrayToJson(paramObject);
            }
            if ((paramObject instanceof Map))
            {
              paramObject = mapToJson((Map)paramObject);
              return paramObject;
            }
            localObject = paramObject;
            if (!(paramObject instanceof Boolean))
            {
              localObject = paramObject;
              if (!(paramObject instanceof Byte))
              {
                localObject = paramObject;
                if (!(paramObject instanceof Character))
                {
                  localObject = paramObject;
                  if (!(paramObject instanceof Double))
                  {
                    localObject = paramObject;
                    if (!(paramObject instanceof Float))
                    {
                      localObject = paramObject;
                      if (!(paramObject instanceof Integer))
                      {
                        localObject = paramObject;
                        if (!(paramObject instanceof Long))
                        {
                          localObject = paramObject;
                          if (!(paramObject instanceof Short))
                          {
                            localObject = paramObject;
                            if (!(paramObject instanceof String)) {
                              if (paramObject.getClass().getPackage().getName().startsWith("java."))
                              {
                                paramObject = paramObject.toString();
                                return paramObject;
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
          catch (Exception paramObject) {}
        }
      }
    }
    return null;
  }
  
  public static JSONArray arrayToJson(Object paramObject)
    throws JSONException
  {
    if (!paramObject.getClass().isArray()) {
      throw new JSONException("Not a primitive data: " + paramObject.getClass());
    }
    int j = Array.getLength(paramObject);
    JSONArray localJSONArray = new JSONArray();
    int i = 0;
    while (i < j)
    {
      localJSONArray.put(a(Array.get(paramObject, i)));
      i += 1;
    }
    return localJSONArray;
  }
  
  public static JSONArray collectionToJson(Collection paramCollection)
  {
    JSONArray localJSONArray = new JSONArray();
    if (paramCollection != null)
    {
      paramCollection = paramCollection.iterator();
      while (paramCollection.hasNext()) {
        localJSONArray.put(a(paramCollection.next()));
      }
    }
    return localJSONArray;
  }
  
  public static JSONObject mapToJson(Map<?, ?> paramMap)
  {
    JSONObject localJSONObject = new JSONObject();
    if (paramMap == null) {
      return new JSONObject();
    }
    paramMap = paramMap.entrySet().iterator();
    while (paramMap.hasNext())
    {
      Map.Entry localEntry = (Map.Entry)paramMap.next();
      String str = (String)localEntry.getKey();
      if (str == null) {
        throw new NullPointerException("key == null");
      }
      try
      {
        localJSONObject.put(str, a(localEntry.getValue()));
      }
      catch (JSONException localJSONException)
      {
        localJSONException.printStackTrace();
      }
    }
    return localJSONObject;
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/com/arellomobile/android/push/utils/JsonUtils.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */