मैं अपने ऐप में webservices का उपयोग कर रहा हूं। असल में मेरा ऐप वर्डप्रेस साइट की एक पोस्ट दिखाता है। उपयोगकर्ता पोस्ट को बुकमार्क भी कर सकता है। मैं पोस्ट यूआरएल के साथ एसक्लाइट में सभी पुस्तक चिह्न पोस्ट सहेज रहा हूं। अब समस्या यह है कि मेरे पास कई अलग-अलग यूआरएल हैं। और मैं इन यूआरएल की सामग्री को एक ListView
में दिखाना चाहता हूं।1 से अधिक विभिन्न यूआरएल और केवल एक सूचीदृश्य
इन सभी यूआरएल की जेसन संरचना भी वही है।
मैं इस मुद्दे से संबंधित अन्य प्रश्न पर ध्यान दिया है, लेकिन उन बहुत मदद नहीं कर रहे हैं।
मुझे आपको दिखाएं कि मैंने अब तक कितना प्रयास किया है।
यहाँ कोड इस यहाँ BookmarkActivity
ArrayList<HashMap<String,String>> allData;
String[] urlarray;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bookmark);
SqliteController controller= new SqliteController(this);
allData = controller.getAllData();
for (int i=0; i<allData.size(); i++){
String url=allData.get(i).get("link");
urlarray= new String[]{url};
}
for(int i=0; i <urlarray.length; i++){
MyAsyncTask task = new MyAsyncTask(i);
task.execute();
}
}
private class MyAsyncTask extends AsyncTask<Object,Void,String>{
int urlNumber;
HttpURLConnection connection=null;
BufferedReader reader=null;
public MyAsyncTask (int number){
this.urlNumber=number;
}
@Override
protected String doInBackground(Object... params) {
try {
URL url = new URL(urlarray[urlNumber]);
connection= (HttpURLConnection) url.openConnection();
connection.connect();
StringBuffer buffer = new StringBuffer();
String line = "";
while ((line = reader.readLine()) != null) {
buffer.append(line);
}
String json = buffer.toString();
return json;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
//Log.d("TAG",s);
}
}
का कोड है json है। (अपने नहीं ठीक उसी json लेकिन मुझे यकीन है कि हर यूआरएल एक ही json संरचना होगा हूँ)
{
"status": "ok",
"count": 1,
"count_total": 1,
"pages": 1,
"posts": [
{
"id": 1,
"type": "post",
"slug": "hello-world",
"url": "http:\/\/localhost\/wordpress\/?p=1",
"title": "Hello world!",
"title_plain": "Hello world!",
"content": "<p>Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!<\/p>\n",
"excerpt": "Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!\n",
"date": "2009-11-11 12:50:19",
"modified": "2009-11-11 12:50:19",
"categories": [],
"tags": [],
"author": {
"id": 1,
"slug": "admin",
"name": "admin",
"first_name": "",
"last_name": "",
"nickname": "",
"url": "",
"description": ""
},
"comments": [
{
"id": 1,
"name": "Mr WordPress",
"url": "http:\/\/wordpress.org\/",
"date": "2009-11-11 12:50:19",
"content": "<p>Hi, this is a comment.<br \/>To delete a comment, just log in and view the post's comments. There you will have the option to edit or delete them.<\/p>\n",
"parent": 0
}
],
"comment_count": 1,
"comment_status": "open"
}
]
}
किसी ने मुझसे इस के साथ मदद कर सकते हैं। मुझे ऐसी स्थिति के साथ कैसे काम करना चाहिए?
आप सूची – Vishwa
ठीक इंतजार से URL में से एक से एक json पोस्ट कर सकते हैं। मुझे –
पोस्ट करने दें मेरे प्रश्न को अपडेट करें। कृपया इसे देखें –