2015-05-06 3 views

ответ

0

Я думаю, что вы можете написать конвертер, как этот

public class ConvertToJson { 
    public static void main(String[] args) { 
     String a = "id=1&location=india"; 
     System.out.println(convert(a)); 
    } 

    private static String convert(String a) { 
     String res = "{\""; 

     for (int i = 0; i < a.length(); i++) { 
      if (a.charAt(i) == '=') { 
       res += "\"" + ":" + "\""; 
      } else if (a.charAt(i) == '&') { 
       res += "\"" + "," + "\""; 
      } else { 
       res += a.charAt(i); 
      } 
     } 
     res += "\"" + "}"; 
     return res; 
    } 
} 

это может сделать работу для вас

1

попробовать это ..

try 
    { 
     String query="id=1&location=india"; 
     String queryArray[]=query.split("&"); 
     String id[]=queryArray[0].split("="); 
     String location[]=queryArray[1].split("="); 

     JSONObject jsonObject=new JSONObject(); 
     jsonObject.put(id[0],id[1]); 
     jsonObject.put(location[0],location[1]); 

     Log.i("Stackoverflow",jsonObject.toString()); 
    } 
    catch (JSONException e) 
    { 
     e.printStackTrace(); 
     Log.i("Stackoverflow",e.getMessage()); 
    }