رفتن به مطلب

bahamin777

کاربر عادی
  • تعداد ارسال ها

    3
  • تاریخ عضویت

  • آخرین بازدید

درباره bahamin777

  • تاریخ تولد تعیین نشده

دستاورد های bahamin777

مبتدی

مبتدی (1/14)

  • Reacting Well
  • First Post
  • Week One Done
  • One Month Later
  • One Year In

نشان‌های اخیر

0

اعتبار در سایت

  1. ممنونم از پیگیریتون لینک فایل جیسون PHP <?php /** * Created by PhpStorm. * User: shahab * Date: 8/29/2016 * Time: 9:02 PM */ $con = mysqli_connect('localhost','mrtshirt_bahamin','Bahamin123456','mrtshirt_masaf'); mysqli_set_charset($con,"(utf-8"); ?> ====== <?php /** * Created by PhpStorm. * User: shahab * Date: 8/29/2016 * Time: 9:04 PM */ require 'db.php'; $result = $con->query("SELECT * FROM masaf"); if($result->num_rows > 0){ $myOut = array(); while($row = $result->fetch_assoc()){ $satr = array(); $satr['id'] = $row["id"]; $satr['name'] = $row["name"]; $satr['desc'] = $row["desc"]; $satr['text'] = $row["text"]; $satr['pic'] = $row["pic"]; $myOut[] = $satr; } echo json_encode($myOut); }else{ echo "ther is no data"; } ?> MainActivity public class Activity_Revayat extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_revayat); final RecyclerView rc = (RecyclerView) findViewById(R.id.rc); final RequestQueue myQueue = Volley.newRequestQueue(Activity_Revayat.this); String url = "http://mrtshirt.ir/masaf/selectAll.php"; final StringRequest myString = new StringRequest(StringRequest.Method.POST,url, new Response.Listener<String>() { @Override public void onResponse(String s) { //s ="[{\"id\":\"1\",\"name\":\"testttt\",\"desc\":\"desccc\",\"text\":\"texttt\",\"pic\":\"picccc\"},{\"id\":\"2\",\"name\":\"nameee\",\"desc\":\"desccc\",\"text\":\"textttt\",\"pic\":\"piccc\"}]"; Log.d("bahamin",s); if (s.equals("ther is no data")) { Toast.makeText(Activity_Revayat.this, "خطا در گرفتن اطلاعات", Toast.LENGTH_SHORT).show(); } else { try { JSONArray myJsonArray = new JSONArray(s); rc.setAdapter(new MyAdapter(Activity_Revayat.this, myJsonArray)); rc.setLayoutManager(new LinearLayoutManager(Activity_Revayat.this, LinearLayoutManager.VERTICAL, false)); } catch (JSONException e) { e.printStackTrace(); } } } }, null) { @Override public byte[] getBody() throws AuthFailureError { try { return ("").getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return null; } } }; myQueue.add(myString); myQueue.start(); } } Adapter public class MyAdapter extends RecyclerView.Adapter<MyAdapter.VH> { private Context c; private JSONArray myArray; public MyAdapter(Context c, JSONArray j) { this.c = c; this.myArray = j; } @Override public VH onCreateViewHolder(ViewGroup parent, int viewType) { return new VH(LayoutInflater.from(c).inflate((R.layout.adapter_layout), parent, false)); } @Override public void onBindViewHolder(VH holder, final int position) { try { JSONObject myObject = myArray.getJSONObject(position); holder.myId.setText(myObject.getString("id")); holder.Name.setText(myObject.getString("name")); holder.User_post.setText(myObject.getString("desc")); holder.Age.setText(myObject.getString("text")); holder.LastName.setText(myObject.getString("pic")); } catch (JSONException e) { e.printStackTrace(); } } @Override public int getItemCount() { return myArray.length(); } class VH extends RecyclerView.ViewHolder { TextView myId; TextView Name; TextView User_post; TextView LastName; TextView Age; public VH(View itemView) { super(itemView); myId = (TextView) itemView.findViewById(R.id.idText); Name = (TextView) itemView.findViewById(R.id.NameText); User_post = (TextView) itemView.findViewById(R.id.PostText); LastName = (TextView) itemView.findViewById(R.id.LastNameText); Age = (TextView) itemView.findViewById(R.id.AgeText); } } }
  2. اقای اسکندری هاست هم خریدم ولی هنوز تو json ام چنین  چنین چیزی موجوده...دقبقا اول رشته
  3. سلام من وقتی میخوام جیسونم رو بگیرم کنارش یه سری کاراکتر های اضافی داره که باعث میشه نتونم ازش استفاده کنم. که چنین چیزی هست===>> "} error ای هم که در logcat میده ===>> Value of type java.lang.String cannot be converted to JSONObject
×
×
  • اضافه کردن...