2014-09-23 142 views
1

這是activity .. plss help ..它不會出現在我的textview ..我在這裏要做的是顯示管理員的配置文件在點擊配置文件選項中導航抽屜..在此先感謝..如何在textview中顯示json對象

請您評論你如何解決這個建議..

public class Profile extends Fragment{ 
    int success; 
View profile; 
JSONParser jsonParser = new JSONParser(); 
JSONObject json; 
TextView tvName,tvNumber,tvEmail,tvUsername,tvPass,tvAddress; 
String adminName, adminNumber,adminEmail,adminUsername,adminPassword,adminAddress; 

private static final String PROFILE_URL = "http://jcasim.5gbfree.com/Project/JCASIM_Api/profile.php"; 
private static final String TAG_SUCCESS = "success"; 
// private static final String TAG_ID = "id"; 



public Profile(){} 
@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
     Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    View profile = inflater.inflate(R.layout.profile, container,false); 
    tvName = (TextView)profile.findViewById(R.id.tvAdminName); 
    tvNumber = (TextView)profile.findViewById(R.id.tvAdminNumber); 
    tvEmail = (TextView)profile.findViewById(R.id.tvAdminEmail); 
    tvUsername = (TextView)profile.findViewById(R.id.tvAdminUsername); 
    tvPass = (TextView)profile.findViewById(R.id.tvAdminPassword); 
    tvAddress = (TextView)profile.findViewById(R.id.tvAdminAddress); 

    new profile().execute(); 
    return profile; 
} 
class profile extends AsyncTask<String, String, String>{ 
    @Override 
    protected String doInBackground(String... arg0) { 
     // TODO Auto-generated method stub 
     String addminObject =""; 
     List<NameValuePair> params = new ArrayList<NameValuePair>(); 
     params.add(new BasicNameValuePair("addminObject", addminObject)); 
     json = jsonParser.makeHttpRequest(PROFILE_URL, "POST",params); 
     try { 
      // json success tag 
      success = json.getInt(TAG_SUCCESS); 
     } catch (JSONException e) { 
      e.printStackTrace(); 
     } 
     return null; 

    } 
    @Override 
    protected void onPostExecute(String result) { 
     // TODO Auto-generated method stub 
     if (success == 1){ 
      try { 
       JSONArray myarr = json.getJSONArray("addminObject"); 

       for(int i =0; i<myarr.length();i++){ 
        JSONObject s = myarr.getJSONObject(i); 

        String adminName = s.getString("CompleteName"); 
        String adminNumber = s.getJSONObject("1").getString("Number"); 
        String adminEmail = s.getJSONObject("2").getString("Email"); 
        String adminUsername = s.getJSONObject("3").getString("Username"); 
        String adminPassword = s.getJSONObject("4").getString("Password"); 
        String adminAddress = s.getJSONObject("5").getString("Address"); 


        tvName.setText(adminName); 
        tvNumber.setText(adminNumber); 
        tvEmail.setText(adminEmail); 
        tvUsername.setText(adminUsername); 
        tvPass.setText(adminPassword); 
        tvAddress.setText(adminAddress); 
       } 

      } catch (JSONException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 


     } 
    } 

,這裏是我的json ..

{"success":1,"addminObject":[{"CompleteName":"Joenevie V.Almonte","Number":"09167801027","Email":"[email protected]","Username":"admin","Password":"pass","Address":"Sa puso ng mahal ko .. :)"}]} 

回答

0

你正在做它錯誤。它應該是這樣的。

String adminName = s.getString("CompleteName"); 
    String adminNumber = s.getString("Number"); 
    String adminEmail = s.getString("Email"); 
    String adminUsername = s.getString("Username"); 
    String adminPassword = s.getString("Password"); 
    String adminAddress = s.getString("Address"); 
+0

太感謝你了..:3 – qazplm 2014-09-23 17:56:26

0
HashMap<String, String> modelItem = new HashMap<>(); 

// adding each child node to HashMap key => value 
modelItem.put("oId", ID); 
modelItem.put("offenceName", offencename1); 
modelItem.put("amount", amount); 

// adding contact to contact list 
contactList.add(modelItem); 

id.setText(ID); 
offence.setText(offencename1); 
amt.setText(amount); 
+0

請詳細說明如何回答這個問題。 – laalto 2017-10-09 10:20:08