小编Mar*_*eld的帖子

在J2ME中解析JSON

所以,我一直在尝试解析这个嵌套的JSON字符串.如果这是普通的Java,甚至是PHP,我相信很久以前就已经完成了.不幸的是,我坚持使用J2ME.通过一些搜索,我发现有一个单独的JSON解析器.我通过对类似问题的一些挖掘发现了这一点.我自己尝试了一些工作,并举了另一个问题的例子.但是,我仍然遇到一些困难.我现在解释一下.

这是我正在尝试解析的JSON字符串:

{"Result":"Success","Code":"200","CustomerInfo":"{\"clientDisplay\":{\"customerId\":429,\"globalCustNum\":\"0012-000000429\",\"displayName\":\"Hugo Daley\",\"parentCustomerDisplayName\":\"G-KINGSTON\",\"branchId\":12,\"branchName\":\"Bangalore_branch1244724101456\",\"externalId\":\"123000890\",\"customerFormedByDisplayName\":\"New User1244724101456\",\"customerActivationDate\":\"2012-06-17\",\"customerLevelId\":1,\"customerStatusId\":3,\"customerStatusName\":\"Active\",\"trainedDate\":null,\"dateOfBirth\":\"1950-10-10\",\"age\":61,\"governmentId\":\"100000090\",\"clientUnderGroup\":true,\"blackListed\":false,\"loanOfficerId\":17,\"loanOfficerName\":\"New User1244724101456\",\"businessActivities\":null,\"handicapped\":null,\"maritalStatus\":null,\"citizenship\":null,\"ethnicity\":null,\"educationLevel\":null,\"povertyStatus\":null,\"numChildren\":null,\"areFamilyDetailsRequired\":false,\"spouseFatherValue\":null,\"spouseFatherName\":null,\"familyDetails\":null},\"customerAccountSummary\":{\"globalAccountNum\":\"001200000001259\",\"nextDueAmount\":\"2128.0\"},\"clientPerformanceHistory\":{\"loanCycleNumber\":0,\"lastLoanAmount\":\"0.0\",\"noOfActiveLoans\":0,\"delinquentPortfolioAmount\":\"0.0\",\"totalSavingsAmount\":\"1750.0\",\"meetingsAttended\":0,\"meetingsMissed\":0,\"loanCycleCounters\":[],\"delinquentPortfolioAmountInvalid\":false},\"address\":{\"displayAddress\":null,\"city\":\"\",\"state\":\"\",\"zip\":\"\",\"country\":\"\",\"phoneNumber\":\"\"},\"recentCustomerNotes\":[{\"commentDate\":\"2012-06-17\",\"comment\":\"appr\",\"personnelName\":\"New User1244724101456\"}],\"customerFlags\":[],\"loanAccountsInUse\":[{\"globalAccountNum\":\"001200000001262\",\"prdOfferingName\":\"Hawker Loan\",\"accountStateId\":3,\"accountStateName\":\"Application Approved\",\"outstandingBalance\":\"15643.0\",\"totalAmountDue\":\"8977.0\"},{\"globalAccountNum\":\"001200000001279\",\"prdOfferingName\":\"Hazina Micro Loan\",\"accountStateId\":2,\"accountStateName\":\"Application Pending Approval\",\"outstandingBalance\":\"6439.0\",\"totalAmountDue\":\"1716.0\"},{\"globalAccountNum\":\"001200000001280\",\"prdOfferingName\":\"Car Finance\",\"accountStateId\":3,\"accountStateName\":\"Application Approved\",\"outstandingBalance\":\"381.5\",\"totalAmountDue\":\"120.0\"}],\"savingsAccountsInUse\":[{\"globalAccountNum\":\"001200000001260\",\"prdOfferingName\":\"Current Account\",\"accountStateId\":16,\"accountStateName\":\"Active\",\"savingsBalance\":\"1750.0\",\"prdOfferingId\":null}],\"customerMeeting\":{\"meetingSchedule\":\"Recur every 1 Week(s) on Monday\",\"meetingPlace\":\"KINGSTON\"},\"activeSurveys\":false,\"customerSurveys\":[],\"closedLoanAccounts\":[{\"globalAccountNum\":\"001200000001261\",\"prdOfferingName\":\"AUTO LOAN-2\",\"accountStateId\":10,\"accountStateName\":\"Cancel\",\"outstandingBalance\":\"2576.0\",\"totalAmountDue\":\"206.0\"}],\"closedSavingsAccounts\":[]}"}
Run Code Online (Sandbox Code Playgroud)

不要担心这只是样本数据,这里没什么.

现在我需要客户编号,姓名,地址和储蓄账户余额.这是我用来解析它的代码:

public CustomerInfo(String jsonTxt) {
try {
    JSONObject json = new JSONObject(jsonTxt);
        JSONObject customer = json.getJSONObject("CustomerInfo");
    custNo = json.getString("globalCustNum");
    custName = json.getString("displayName");
    address = json.getString("DisplayAddress");
    savAcctBal =  json.getDouble("totalSavingsAmount");
} catch (final JSONException je) {
        je.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)

这当然会抛出JSONException.我了解到JSON库可能有一些错误.我用打印语句做了一些技巧.事实证明,它喜欢使用JSON字符串的第一个元素.这会严重影响嵌套元素,就像我们在示例中所见.

有没有我可以使用的替代方案?

java parsing json java-me

5
推荐指数
1
解决办法
2128
查看次数

Spring Data Neo4j 中的自定义查询不检索关系

因此,对于一些复杂的操作,我在图形存储库中的自定义查找器方法上使用 @Query 注释使用自定义 Cypher 查询。然而,当它检索节点时,它不会检索其直接关系(即只有 1 个级别)。

@Query("match (node:T) return node Order by node.requestedAt Desc LIMIT 100")
List<T> last100T();

@Query("match (node:T) where node.status = \"REQUESTED\" and  timestamp() - node.requestedAt >= 60000 return node")
List<Transit> findUnmatchedAndExpiredT();
Run Code Online (Sandbox Code Playgroud)

我是这样使用它们的 - (代码在 groovy 中):

 def nodes = TRepository.findUnmatchedAndExpiredT()
    nodes.forEach({
        node ->
            node.status = TStatus.DECLINED
            node.neighbourA.status = NeighbourAStatus.BARRED
            def neighbourBQueue = client.queue(node.neighbourB.username)
            neighbourBQueue.push(mapper.writeValueAsString(node))

    TRepository.save(node)
})
Run Code Online (Sandbox Code Playgroud)

它们的关系如下:

    @NodeEntity
class T{

    public T(){
    }

    @GraphId
    Long id

    @Relationship(type = "REQUESTED_BY", direction = Relationship.OUTGOING)
    NeighbourB neighbourB

    @Relationship(type = …
Run Code Online (Sandbox Code Playgroud)

java groovy spring spring-data-neo4j-4 neo4j-ogm

3
推荐指数
1
解决办法
3868
查看次数

标签 统计

java ×2

groovy ×1

java-me ×1

json ×1

neo4j-ogm ×1

parsing ×1

spring ×1

spring-data-neo4j-4 ×1