解析此Json数组并提取text的值

时间:2019-07-02 07:29:52

标签: arrays json parsing

这是我要解析并提取具有值text的{​​{1}}的完整json。

有人可以帮忙吗?

The product is in second line 3rd row

1 个答案:

答案 0 :(得分:0)

您已指定这是您在问题中放置的完整json,但是您缺少的内容不是完整json。

"activities": 
   [     //json array start from here                                          
    {                                                         
      "type": "message",                                      
      "id": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",               
      "timestamp": "2019-07-01T15:18:56.8251462Z",            
      "serviceUrl": "XXXXXXXXXXXXXXXXXXXXXXXXX",   
      "channelId": "directline",                              
      "from": {                                               
        "id": "user1"                                         
      },                                                      
      "conversation": {                                       
        "id": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX"                      
      },                                                      
      "text": "the milk"                                      
    },                                                        
    {                                                         
      "type": "message",                                      
      "id": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",               
      "timestamp": "2019-07-01T15:18:57.6856172Z",            
      "localTimestamp": "2019-07-01T15:18:57.5099359+00:00",  
      "channelId": "directline",                              
      "from": {                                               
        "id": "XXXXXX",                                        
        "name": "XXXXXX"                                       
      },                                                      
      "conversation": {                                       
        "id": "XXXXXXXXXXXXXXXXXX"                      
      },                                                      
      "text": "The product is in second line 3rd row",        
      "attachments": [],                                      
      "entities": [],                                         
      "replyToId": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX"         
    } 

  ],      //json array ends here



    these are extra lines                                                 
  ***"watermark": "1"                                            
}***

如果要使用此数组,则需要在

前的最顶行添加一个'{'

“活动”:[

我现在将有效的json放在这里,您可以在Json parser used to parse json in objects上对其进行检查

*有效Json在这里:*

{
"activities": [                                             
    {                                                         
      "type": "message",                                      
      "id": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",               
      "timestamp": "2019-07-01T15:18:56.8251462Z",            
      "serviceUrl": "XXXXXXXXXXXXXXXXXXXXXXXXX",   
      "channelId": "directline",                              
      "from": {                                               
        "id": "user1"                                         
      },                                                      
      "conversation": {                                       
        "id": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX"                      
      },                                                      
      "text": "the milk"                                      
    },                                                        
    {                                                         
      "type": "message",                                      
      "id": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",               
      "timestamp": "2019-07-01T15:18:57.6856172Z",            
      "localTimestamp": "2019-07-01T15:18:57.5099359+00:00",  
      "channelId": "directline",                              
      "from": {                                               
        "id": "XXXXXX",                                        
        "name": "XXXXXX"                                       
      },                                                      
      "conversation": {                                       
        "id": "XXXXXXXXXXXXXXXXXX"                      
      },                                                      
      "text": "The product is in second line 3rd row",        
      "attachments": [],                                      
      "entities": [],                                         
      "replyToId": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX"         
    }                                                         
  ],                                                          
  "watermark": "1"                                            
}