2017-10-12 3 views
-1

Cela fait partie de mon JSON (dans l'original, j'ai beaucoup mêmes parties):Comment valider et obtenir des données de JSON comme ceci avec le repos assuré?

{ 
    "content": [ 
    { 
     "id": "20d4719a9-5636236-1015a2626e78", 
     "title": "CONC", 
     "filename": "3543543634634.ts", 
     "resolution": "4k", 
     "details": { 
     "description": "CC", 
     "genres": [ 
      "standard" 
     ], 
     "duration": "107", 
     "release": "Jan 26 2014 11:01AM", 
     "tags": "043543534534", 
     "rating": "G", 
     "expires": "25235353460", 
     "added": "150353535724113", 
     "frameRate": "60", 
     "type": "br-ca", 
     "deletable": "true", 
     "outputRange": "sdr", 
     "outputResolution": "4k", 
     "enabledDate": "1335353420", 
     "channel": "", 
     "actionId": "playback", 
     "resolution": "4k", 
     "supportedResolutions": "4k", 
     "supportedModels": "", 
     "unsupportedModels": "", 
     "supportedAudioModels": "", 
     "audioLevel": "0", 
     "fileId": "58ba025325252001ea263", 
     "metadata": null, 
     "bitdepth": "b8", 
     "colorspace": "cAuto", 
     "artist": "N\/A", 
     "album": "" 
     }, 
     "status": { 
     "state": "playable", 
     "download": { 
      "size": "62713254232", 
      "bytes": 0, 
      "position": -1 
     }, 
     "playback": { 
      "viewCount": "0", 
      "position": "0" 
     } 
     }, 
     "categories": [ 
     { 
      "id": "b91667fjhfg07457ff", 
      "name": "HOME", 
      "language": "br-ca", 
      "translation": "HOME", 
      "state": "playable" 
     } 
     ], 
     "images": [ 
     { 
      "id": "7c9anx5y4u44u433u5b3d3ccf3", 
      "uri": "041thddhdhdhdrh.png", 
      "width": "232", 
      "height": "131", 
      "row": "0", 
      "column": "0", 
      "action": "button" 
     }, 
     { 
      "id": "dhsdhrdrhdr54y6y", 
      "uri": "dfhe45h334.png", 
      "width": "294", 
      "height": "160", 
      "row": "1", 
      "column": "1", 
      "action": "playback" 
     }, 
     { 
      "id": "hrh35h3h333h", 
      "uri": "3h33h3h3hdfhdhd.png", 
      "width": "294", 
      "height": "160", 
      "row": "1", 
      "column": "2", 
      "action": "loop" 
     }, 
     { 
      "id": "3y3y3g3g43g3", 
      "uri": "fghfghf554h5445h.png", 
      "width": "294", 
      "height": "160", 
      "row": "1", 
      "column": "3", 
      "action": "loop" 
     }, 
     { 
      "id": "54h45h54h54h", 
      "uri": "fjfgj464545g35demo.png", 
      "width": "294", 
      "height": "160", 
      "row": "2", 
      "column": "1", 
      "action": "loop" 
     }, 

... 

Je dois trouver toutes les catégories , où le nom == "HOME". Et pour ces catégories, prenez le nom de contenu (content.name)

Même nécessité pour les autres catégories. Donc, je veux avoir trié par catégorie et imprimé avec des noms de contenu.

Pour la validation j'ai ce code, mais ressemble à quelque chose de mal, parce que le nom de validation == "HOME" ne fonctionne pas.

package GET; 


import org.testng.annotations.Test; 
import java.util.List; 
import static io.restassured.RestAssured.get; 
import static io.restassured.path.json.JsonPath.from; 


public class GetContent { 

    @Test 
    public void parseContent() { 

     String response = get("http://192.168.1.139/v1/content/").asString(); 

     List<String> list = from(response).getList("content.categories.findAll {it.name == 'HOME'}.name"); 

     int a = list.size(); 
     System.out.println("List Size: " + a); 

     System.out.println(list); 
    } 

Avez-vous des idées? Merci.

Répondre

0

Essayez ce code:

let results = your_object.content.map(e => { 
    if(e.categories[0].name === "HOME") { 
     return e.categories[0].id; // whatever you want 
    } 
});