首页 \ 问答 \ 如何比较整数字段和json字段?(How to compare integer field with json field?)

如何比较整数字段和json字段?(How to compare integer field with json field?)

我有以下json响应,从这个响应我得到unitprice和boxqty,1500和1在两个不同的edittext,现在我正在尝试的是如果用户将boxqty从1更改为15,那么单价应该从1500更改为1470 ,以下是我的代码片段,

{"status":"success","clientproduct":[{"pid":"4","name":"kangan pair","unitprice":"1500","boxqty":"1","bulkprice":[{"minqty":"10","price":"1500"},{"minqty":"15","price":"1470"},{"minqty":"20","price":"1460"}]}]}

MainActivity.java

     @Override
    protected String doInBackground(String...args) {
        //Check for success tag
        //int success;
        Looper.prepare();

         try {
             List<NameValuePair> params = new ArrayList<NameValuePair>();
             params.add(new BasicNameValuePair("cid",letss));
             params.add(new BasicNameValuePair("action", "clientproduct"));

             System.out.println("su gayu server ma????"+params);

             Log.d("request!", "starting");
             // getting product details by making HTTP request
             JSONObject json = jsonParser.makeHttpRequest (
                 FEEDBACK_URL, "POST", params);
             //check your log for json response
             Log.d("Login attempt", json.toString());
            if (json != null) {
                try {
                    JSONObject jsonObj = new JSONObject(json.toString());
                    // Getting JSON Array node
                    clientproduct = jsonObj.getJSONArray(CLIENTPRODUCT_LIST);
                    // looping through All Contacts
                    for (int i = 0; i < clientproduct.length(); i++) {
                       ck = clientproduct.getJSONObject(i);
                       unitp=ck.getString("unitprice");
                        System.out.println("Unit ni price"+unitp);
                       boxq=ck.getString("boxqty");
                        System.out.println("Box ni quantity "+boxq);

                        bulkprice = ck.getJSONArray(BULKPRICE_LIST);

                        allqtys=new ArrayList<Integer>();
                         for (int b=0 ; b < bulkprice.length(); b++)
                         {
                             jo = bulkprice.getJSONObject(b);

                           minimum_qty=jo.getInt("minqty");
                        allqtys.add(minimum_qty);
                            /* allqtys=new ArrayList<String>();
                           allqtys.add(minimum_qty.toString());
                          System.out.println("All MinQuantitiy"+minimum_qty);*/
                     System.out.println("All MinQuantitiy"+allqtys);
                       System.out.println("MinQuantitiy"+minimum_qty);

                           pricess=jo.getString("price");
                            System.out.println("Box price "+pricess);

                         }
                         /*conrs=Integer.parseInt(allqtys.toString());
                         System.out.println("Integer converted arrray"+conrs);*/

                        /* newList = new ArrayList<Integer>(allqtys.size()) ;
                         for (String myInt : allqtys) 
                         { 
                           newList.add(Integer.valueOf(myInt)); 
                         }
                         System.out.println("allqtys "+newList);*/

                        System.out.println("Not Null");
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            } else {
                Log.e("ServiceHandler", "Couldn't get any data from the url");
            }


         return json.getString(FEEDBACK_SUCCESS);

     }catch (JSONException e) {
         e.printStackTrace();
     }
     return null;
}

    // After completing background task Dismiss the progress dialog

    protected void onPostExecute(String file_url) {
        //dismiss the dialog once product deleted
        pDialog.dismiss();

       /* ArrayList<Integer> allval=new ArrayList<Integer>();
       // allval.add(minimum_qty);
       System.out.println("Integer converted arraylist"+allval);*/


        autoproduct.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                // TODO Auto-generated method stub
                // uprice.setText(unitp);
                    //bxqtyy.setText(boxq);
            }
        });


        bxqtyy.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                // TODO Auto-generated method stub
                if(Integer.parseInt(bxqtyy.getText().toString()) > Integer.parseInt(allqtys.get(index)))
                {
                    if(bxqtyy.getText().equals(null))
                    {
                        uprice.setText(unitp);
                    }
                    uprice.setText("1470");
                    //System.out.println("lets check");
                }
                else
                {
                    uprice.setText("1500");
                    System.out.println("lets check");
                }
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

}}

I have following json response,from this response I am getting unitprice and boxqty, 1500 and 1 in two different edittext,now what I am trying is if user will change boxqty from 1 to 15,then unit price should be change from 1500 to 1470,following is my code snippet,

{"status":"success","clientproduct":[{"pid":"4","name":"kangan pair","unitprice":"1500","boxqty":"1","bulkprice":[{"minqty":"10","price":"1500"},{"minqty":"15","price":"1470"},{"minqty":"20","price":"1460"}]}]}

MainActivity.java

     @Override
    protected String doInBackground(String...args) {
        //Check for success tag
        //int success;
        Looper.prepare();

         try {
             List<NameValuePair> params = new ArrayList<NameValuePair>();
             params.add(new BasicNameValuePair("cid",letss));
             params.add(new BasicNameValuePair("action", "clientproduct"));

             System.out.println("su gayu server ma????"+params);

             Log.d("request!", "starting");
             // getting product details by making HTTP request
             JSONObject json = jsonParser.makeHttpRequest (
                 FEEDBACK_URL, "POST", params);
             //check your log for json response
             Log.d("Login attempt", json.toString());
            if (json != null) {
                try {
                    JSONObject jsonObj = new JSONObject(json.toString());
                    // Getting JSON Array node
                    clientproduct = jsonObj.getJSONArray(CLIENTPRODUCT_LIST);
                    // looping through All Contacts
                    for (int i = 0; i < clientproduct.length(); i++) {
                       ck = clientproduct.getJSONObject(i);
                       unitp=ck.getString("unitprice");
                        System.out.println("Unit ni price"+unitp);
                       boxq=ck.getString("boxqty");
                        System.out.println("Box ni quantity "+boxq);

                        bulkprice = ck.getJSONArray(BULKPRICE_LIST);

                        allqtys=new ArrayList<Integer>();
                         for (int b=0 ; b < bulkprice.length(); b++)
                         {
                             jo = bulkprice.getJSONObject(b);

                           minimum_qty=jo.getInt("minqty");
                        allqtys.add(minimum_qty);
                            /* allqtys=new ArrayList<String>();
                           allqtys.add(minimum_qty.toString());
                          System.out.println("All MinQuantitiy"+minimum_qty);*/
                     System.out.println("All MinQuantitiy"+allqtys);
                       System.out.println("MinQuantitiy"+minimum_qty);

                           pricess=jo.getString("price");
                            System.out.println("Box price "+pricess);

                         }
                         /*conrs=Integer.parseInt(allqtys.toString());
                         System.out.println("Integer converted arrray"+conrs);*/

                        /* newList = new ArrayList<Integer>(allqtys.size()) ;
                         for (String myInt : allqtys) 
                         { 
                           newList.add(Integer.valueOf(myInt)); 
                         }
                         System.out.println("allqtys "+newList);*/

                        System.out.println("Not Null");
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            } else {
                Log.e("ServiceHandler", "Couldn't get any data from the url");
            }


         return json.getString(FEEDBACK_SUCCESS);

     }catch (JSONException e) {
         e.printStackTrace();
     }
     return null;
}

    // After completing background task Dismiss the progress dialog

    protected void onPostExecute(String file_url) {
        //dismiss the dialog once product deleted
        pDialog.dismiss();

       /* ArrayList<Integer> allval=new ArrayList<Integer>();
       // allval.add(minimum_qty);
       System.out.println("Integer converted arraylist"+allval);*/


        autoproduct.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                // TODO Auto-generated method stub
                // uprice.setText(unitp);
                    //bxqtyy.setText(boxq);
            }
        });


        bxqtyy.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                // TODO Auto-generated method stub
                if(Integer.parseInt(bxqtyy.getText().toString()) > Integer.parseInt(allqtys.get(index)))
                {
                    if(bxqtyy.getText().equals(null))
                    {
                        uprice.setText(unitp);
                    }
                    uprice.setText("1470");
                    //System.out.println("lets check");
                }
                else
                {
                    uprice.setText("1500");
                    System.out.println("lets check");
                }
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

}}

原文:https://stackoverflow.com/questions/29910873
更新时间:2023-10-23 10:10

最满意答案

嗯,这并不容易。 你需要一次做两个动画,比如

//first half of the motion
setTimeout(function(){
    $('.bouquet').animate({left: endPos/2}, 3000,'<easing>');
},0);

setTimeout($('.bouquet').animate({top:offset.top}, 3000,'<easing>',function(){
    //on complete: other half of the motion
    setTimeout(function(){
        $('.bouquet').animate({left: endPos}, 3000,'<easing>');
    },0);
    setTimeout(function(){
        $('.bouquet').animate({top:offset.top}, 3000,'<easing>'
    }),0)
}),0)

具有缓动功能,为左右运动提供二次函数,为上下运动提供线性函数。 否则它只是一条线...但我不确定这些是什么样的缓和,可能有人补充说。 两个setTimeout函数不应该阻塞,因此两个动画应该同时发生

[编辑] ...好吧,我只是尝试了它,似乎不可能同时在一个对象上做多个动画。 但我提出了另一种可能的解决方案:

http://jsfiddle.net/7AHLb/1

它还不完美,但是如果你玩一点,它可能对你有所帮助。


Well, this won't be easy. You'll need to do two animations at once, like

//first half of the motion
setTimeout(function(){
    $('.bouquet').animate({left: endPos/2}, 3000,'<easing>');
},0);

setTimeout($('.bouquet').animate({top:offset.top}, 3000,'<easing>',function(){
    //on complete: other half of the motion
    setTimeout(function(){
        $('.bouquet').animate({left: endPos}, 3000,'<easing>');
    },0);
    setTimeout(function(){
        $('.bouquet').animate({top:offset.top}, 3000,'<easing>'
    }),0)
}),0)

with an easing function that provides a quadratic function for the left-right motion and a linear one for the up-down motion. Else it would just be a line...but i'm not sure about which easings these are, may someone add that. the two setTimeout functions should not block, and thus both animations should happen at the same time

[EDIT] ...okay, i just tried it and it seems impossible to do multiple animations on one object at the same time. but i came up with another possible solution:

http://jsfiddle.net/7AHLb/1

it's not perfect yet, but if you play a bit with it, it might help you.

相关问答

更多
  • 添加对象:有两种方法 - 设置子级的Parent属性或执行父级的AddObject方法。 Parent属性设置器有一些检查,并调用AddObject 。 根据控件类,可以将子对象添加到Controls集合或其Content专用字段中。 并非所有类都提供对此字段的访问权限(在某些情况下,您可以使用变通方法,就像在此问题中一样 )。 HorzScrollBox在公共区域有这个领域。 因此,如果要克隆现有图像,则必须: 从HorzScrollBox Content中获取现有图像 创建新图像并设置其属性 将新图像添 ...
  • 嗯,这并不容易。 你需要一次做两个动画,比如 //first half of the motion setTimeout(function(){ $('.bouquet').animate({left: endPos/2}, 3000,''); },0); setTimeout($('.bouquet').animate({top:offset.top}, 3000,'',function(){ //on complete: other half of th ...
  • 明白了。 去除 $('.overview').delay(1000).queue(function () { features_back(item_clicked); }); 并替换为: setTimeout(function() { features_back(item_clicked); }, 1000); Got it figured out. removed $('.overview').delay(1000).queue(function () { features_b ...
  • 是的,可以使用JS添加预渲染提示,并且可以将url更新为应该预渲染的页面。 基本上,浏览器将“忘记”以前的渲染页面并预渲染一个新页面。 但是,您必须小心,如果浏览器没有足够的时间预渲染结帐页面,用户将看到过期的结帐页面。 考虑到您的情况,您需要使用查询参数,否则,浏览器在更新href属性后不会再次预渲染结账页面,因为它已经在缓存中。 例如,网址可能如下所示: /checkout?timestamp=111111 /checkout?timestamp=222222 /checkout?timestamp=3 ...
  • 如果你正在使用较低级别的库(也就是说,不是pandas的包装器),你可能应该使用它们 hist(antimony.Antimony.values) (有关更多信息,请参阅hist文档)。 If you're using the lower-level libraries (that is, not pandas's wrappers for them), you probably should use hist(antimony.Antimony.values) (see thehist documen ...
  • 中继器不会生成任何自己的HTML。 它只会写你告诉它写的东西。 所以你需要做的是以某种方式识别每个项目,最好在HTML中使用唯一的ID。 这样你就可以通过DOM访问它。 例如,如果呈现的标记看起来像这样,那么你实际上可以通过jquery访问“item1”:
    abc
    def
    要做到这一点,你可以在你的ItemTemplate中尝试这样的事情:
    在Scrapy可以使用extract来获取textual data ,但是如果只想extract first matched element ,则可以调用选择器extract_first() 。 在你的情况下,更新stamp和title选择器需要如下extract_first() : def parse(self, response): for item in response.xpath("//li[contains(@class, 'river-block')]"): url ...
  • 这些复选标记是表情符号,它们在不同的操作系统/平台上有不同的设计。 有关不同版本,请参阅表情符号 。 解决方案是使用您自己的复选标记图形(例如SVG图像)或使用非表情符号复选标记,以便您自己确定颜色。 These checkmarks are emoji, and they're different designs on different OSes/platforms. See Emojipedia for the different version. The solution is to either ...
  • 我认为你需要通过在将它添加到DOM后调用droppable()来使新添加的元素可以删除。 如果你添加这样的东西: $(this).find('#ontheflyDiv').droppable( { ... }); 在你的drop函数的底部它应该工作。 我不知道在页面加载后添加的元素添加droppable功能的方法类似于jquery的live()函数可以对click和其他事件执行的操作。 I think you need to make your newly appended element dr ...
  • 如果所有图像都具有相似的图案,则只需使用轮廓边界矩形的纵横比(宽度/高度)将其过滤掉即可。 即,如果找到所有轮廓的边界矩形,则外形的aspect_ratio接近1。 但U形的aspect_ratio超过10。 下面是一个python代码: import cv2 import numpy as np img = cv2.imread('sofud.jpg') gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) ret,thresh = cv2.threshold(gr ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。