1

在这里,我正在使用将转换drupal site为 android的 android 应用程序native application.在这里我从 android 创建时遇到了问题drupal node。简而言之,我对此一无所知。但是我在下面尝试过,请让我知道我错在哪里,并且还有其他解决方案。

在这段时间里,我还面临另一个问题。在我的 postIdea 类中,还有两个AsyncTask(类别和创始人)从 json 加载数据并在按下提交按钮之前添加到微调器。它的工作完美。但是,当按下提交按钮时,还会调用上一个(类别和创始人)AsyncTask。按下提交按钮后,我不会再次调用类别和创始人方法。

在我的情况下,节点的 drupal 接受格式:

{
 "type":"idea",
 "title":"idea one",
 "field_story_idea":[
 {
"value":"test"          // test is title value
}
],
"field_founder_profile_refrence":[
 {
   "nid":"111"             // 111 is founder value
 }
],
"field_idea_budget":[
{
 "value":"2"             // 2 is budget value
 }
 ],
"field_idea_details":[
{
 "value":"AAAAAAAA"     //  AAAAAAAA is idea details value
}
],
"taxonomy":{
  "6":{
"tid":"6"         // 6 is the category value
 }
}
}

在这里,我得到了所有值并转换为JSON format(根据上面的显示)。当我将特定数据传递给服务器时,它给了我状态代码 200,但也给出了如下错误:

    Response from post  idea => <br /><b>Fatal error</b>:  Cannot unset string offsets in <b>/var/aegir/hostmaster-HEAD/profiles/default/modules/cck/includes/content.node_form.inc</b> on line <b>60</b><br />

当我将所有数据组合成一个 jsonobject 并传递给服务器时,它会给出错误 401 状态代码,也会给出如下错误:

 Invalid use of SingleClientConnManager: connection still allocated.
 W/SingleClientConnManager( 1212): Make sure to release the connection before allocating another one.

post_idea.class

public class Post_Idea extends AsyncTask<Void, Void, Void> {

    String strResponse1;
    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub
        super.onPreExecute();

        pgb.setVisibility(View.VISIBLE);
    }

    @Override
    public Void doInBackground(Void... params) {
        // TODO Auto-generated method stub
        String url = "URL HERE...";

        //String strResponse;
        try {

            strResponse1 = util.makeWebForPostIdea(url,title,spinnercategoryIndexId, spinnerFounderIndexId,
                    story_bhnd_idea,idea_dtls, spinnerBudgetId);

            System.out.println("=========> Response from post  idea => "
                    + strResponse1);

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

        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);
        pgb.setVisibility(View.GONE);

    }
}

实用程序类

  public static String makeWebForPostIdea(String url, String title,int spinnercategoryIndexId, int spinnerFounderIndexId, String story_bhnd_idea, String idea_dtls,int spinnerBudgetId) throws JSONException
   {

         HttpPost post = new HttpPost(url);

             List<NameValuePair> params = new ArrayList<NameValuePair>();


            // For the Founder and all other fields covert the json to the stringer

            JSONStringer jsonstringerFounder = new JSONStringer().array().object().key("nid").value(""+spinnerFounderIndexId).endObject().endArray();
            JSONStringer jsonstringerstoryBhndIdea = new JSONStringer().array().object().key("value").value(""+story_bhnd_idea).endObject().endArray();
            JSONStringer jsonstringerIdeaDetails = new JSONStringer().array().object().key("value").value(""+idea_dtls).endObject().endArray();
            JSONStringer jsonstringerBudjet = new JSONStringer().array().object().key("value").value(""+spinnerBudgetId).endObject().endArray();
                JSONStringer jsonstringercategory1 = new JSONStringer().object().key(""+spinnercategoryIndexId).object().key("tid").value(""+spinnercategoryIndexId).endObject().endObject();


            JSONStringer combineallnode123 = new JSONStringer().object().key("type").value("idea").key("title").value(title).key("field_story_idea").
                    value(jsonstringerstoryBhndIdea).key("field_founder_profile_refrence").value(jsonstringerFounder).
                    key("field_idea_budget").value(jsonstringerBudjet).key("field_idea_details").
                    value(jsonstringerIdeaDetails).key("taxonomy").value(jsonstringercategory1).endObject();

           params.add(new BasicNameValuePair("cheerfoolz",combineallnode123.toString()));
          /* params.add(new BasicNameValuePair("type","idea"));
             params.add(new BasicNameValuePair("title",title));
             params.add(new BasicNameValuePair("field_story_idea", jsonstringerstoryBhndIdea.toString()));
             params.add(new BasicNameValuePair("field_founder_profile_refrence",jsonstringerFounder.toString()));
             params.add(new BasicNameValuePair("field_idea_budget", jsonstringerBudjet.toString()));
             params.add(new BasicNameValuePair("field_idea_details",jsonstringerIdeaDetails.toString()));
             params.add(new BasicNameValuePair("taxonomy",jsonstringercategory1.toString())); 
            */             

        UrlEncodedFormEntity formEntity = null;
            try {
                            formEntity = new UrlEncodedFormEntity(params);
            } catch (UnsupportedEncodingException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
            }

         post.setEntity(formEntity);

            try {

                    HttpResponse response = client.execute(post);

                    int statusCode = response.getStatusLine().getStatusCode();
                    System.out.println("=========> statusCode from the postidea util.java=====> "+statusCode);        
                    if (statusCode == HttpStatus.SC_OK)
                    {
                            HttpEntity entity = response.getEntity();
                            //String html = EntityUtils.toString(entity);
                            InputStream is = entity.getContent();

                            return iStream_to_String(is);
                    }
                    else
                    {
                            return "Hello This is status ==> :"+String.valueOf(statusCode);
                    }
            } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
            } catch (ClientProtocolException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
            } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
            }


            }

            return null;

    }

编辑:

在这里,当我将perticular值传递给服务器时,然后给我status code 200,但在drupal site.

4

0 回答 0