wuxw7
2018-06-13 28441b3922e6188f643d145a32c55d4fa285af84
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.java110.log.jsonpath;
 
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPath;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
 
/**
 * Created by wuxw on 2017/4/24.
 */
public class CustIdTest  extends TestCase
{
    /**
     * Create the test case
     *
     * @param testName name of the test case
     */
    public CustIdTest( String testName )
    {
        super( testName );
    }
 
    /**
     * @return the suite of tests being tested
     */
    public static Test suite()
    {
        return new TestSuite( CustIdTest.class );
    }
 
    public void testCustId(){
        String jsonStr = " { \"actionTypeCd\": \"C1\", \"boCust\": [ " +
                "{ \"custId\": \"123\", \"name\": \"S\", \"email\": \"-52\", \"cellphone\": \"17797173942\", \"realName\": \"wuxw\", \"sex\": \"1\", \"password\": \"123456\", \"lanId\": \"863010\", \"custAdress\": \"青海省西宁市城中区格兰小镇\", \"custType\": \"1\", \"openId\": \"\", \"state\": \"ADD\" }, { \"custId\": \"-1\", \"name\": \"S\", \"email\": \"-52\", \"cellphone\": \"17797173942\", \"realName\": \"wuxw\", \"sex\": \"1\", \"password\": \"123456\", \"lanId\": \"863010\", \"custAdress\": \"青海省西宁市城中区格兰小镇\", \"custType\": \"1\", \"openId\": \"\", \"state\": \"DEL\" } ], \"boCustAttr\": [ { \"custId\": \"123\", \"prodId\": \"-1\", \"attrCd\": \"123344\", \"value\": \"1\", \"state\": \"ADD\" }, { \"custId\": \"123\", \"prodId\": \"-1\", \"attrCd\": \"123345\", \"value\": \"1\", \"state\": \"DEL\" } ] } ";
        JSONObject custInfo = JSONObject.parseObject(jsonStr);
        System.out.println(JSONPath.eval(custInfo,"$.boCust[custId < '0'][0].custId"));
    }
}