2016-06-24 23 views
0

を形成こんにちは、私は列の特定のデータを抽出したいどのように列の特定のデータを抽出するためにSoapUi-がJSONレスポンス

{ 
    "New England Schools__NE Schools$": { 
"dsData": "Account Id#%#Territory#%#District#%#Area#%#Region#%#objname#%#~ID~#%#~Lat-Lon Linked~#%#~Latitude~#%#~Longitude~#%#~Lat-Lon Zip~#%#School Name#%#Address#%#City#%#State#%#ZIP#%#ZIP4#%#School Type#%#Status#%#School Level#%#Count Free Lunch#%#Count Reduced Lunch#%#Total Lunch Pgm#%#Total Students#%#PreKindergarten#%#Kindergarten#%#Grade 1#%#Grade 2#%#Grade 3#%#Grade 4#%#Grade 5#%#Grade 6#%#Grade 7#%#Grade 8#%#Grade 9#%#Grade 10#%#Grade 11#%#Grade 12#%#Territory1#%#Region1#%#lat#%#lon#%#terrid\r\n15709#%#Hartford, CT#%#New England#%#Unassigned#%#Unassigned#%#Account#%#15709#%#True#%#41.934711#%#-72.770021#%#06026#%#R. DUDLEY SEYMOUR SCHOOL#%#185 HARTFORD AVENUE#%#EAST GRANBY#%#CT#%#6026#%#9520#%#1#%#1#%#2#%#0#%#0#%#0#%#131#%#0#%#0#%#0#%#0#%#0#%#60#%#71#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#Hartford, CT#%#New England#%#5151204.33051376#%#-8100721.57141633#%#3\r\n15707#%#Hartford, CT#%#New England#%#Unassigned#%#Unassigned#%#Account#%#15707#%#True#%#41.934894#%#-72.730656#%#06026#%#EAST GRANBY HIGH SCHOOL#%#95 SOUTH MAIN STREET#%#EAST GRANBY#%#CT#%#6026#%#9550#%#1#%#1#%#3#%#0#%#0#%#0#%#219#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#57#%#55#%#53#%#54#%#Hartford, CT#%#New England#%#5151231.26605957#%#-8096340.03625871#%#3\r\n15708#%#Hartford, CT#%#New England#%#Unassigned#%#Unassigned#%#Account#%#15708#%#True#%#41.934894#%#-72.730656#%#06026#%#EAST GRANBY MIDDLE SCHOOL#%#95 SOUTH MAIN STREET#%#EAST GRANBY#%#CT#%#6026#%#9550#%#1#%#1#%#2#%#0#%#0#%#0#%#201#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#67#%#73#%#61#%#0#%#0#%#0#%#0#%#Hartford, CT#%#New England#%#5151231.26605957#%#-8096340.03625871#%#3\r\n15706#%#Hartford, CT#%#New England#%#Unassigned#%#Unassigned#%#Account#%#15706#%#True#%#41.944215#%#-72.732696#%#06026#%#ALLGROVE SCHOOL#%#33 TURKEY HILLS ROAD#%#EAST GRANBY#%#CT#%#6026#%#9570#%#1#%#1#%#1#%#0#%#0#%#0#%#275#%#3#%#69#%#65#%#82#%#56#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#Hartford, CT#%#New England#%#5152627.52929053#%#-8096567.12801993#%#3\r\n15710#%#Hartford, CT#%#New England#%#Unassigned#%#Unassigned#%#Account#%#15710#%#True#%#41.944215#%#-72.732696#%#06026#%#HOMEBOUND#%#33 TURKEY HILL ROAD#%#EAST GRANBY#%#CT#%#6026#%#674#%#4#%#3#%#4#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#Hartford, CT#%#New England#%#5152627.52929053#%#-8096567.12801993#%#3\r\n15923#%#Hartford, CT#%#New England#%#Unassigned#%#Unassigned#%#Account#%#15923#%#True#%#42.0027#%#-72.942#%#06027#%#HOMEBOUND#%#30 SOUTH ROAD#%#EAST HARTLAND#%#CT#%#6027#%#9710#%#4#%#3#%#4#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#Hartford, CT#%#New England#%#5161383.89953631#%#-8119866.29744296#%#3\r\n15922#%#Hartford, CT#%#New England#%#Unassigned#%#Unassigned#%#Account#%#15922#%#True#%#42.0027#%#-72.942#%#06027#%#HARTLAND ELEMENTARY SCHOOL#%#30 SOUTH ROAD#%#EAST HARTLAND#%#CT#%#6027#%#9710#%#1#%#1#%#1#%#0#%#0#%#0#%#2#%#0#%#25#%#17#%#26#%#29#%#37#%#36#%#38#%#35#%#40#%#0#%#0#%#0#%#0#%#Hartford, CT#%#New England#%#5161383.89953631#%#-8119866.29744296#%#3\r\n16335#%#} 

JSONレスポンスを形成し、私のGroovyスクリプトが

log.info json."New England Schools__NE Schools\$".dsData 

上記プリントすべてですその中のデータと列のデータはi am not sure how to get column specific dataだと助けてください。

私が望むようにはできません上記の場合は例えば、Territoryは私のコラムであり、その行の値がHartford, CT

あり、そして我々がそうであるように(事のスプリット種類をすべての応答を破る方法を教えてくださいjava)ので、私は特定の値を呼び出すことができますか?詳細に探した後

+0

データが入っているフォーマット/パターンはどれですか?何柱ですか?どんな基準にも従っていないように見えますか? – Rao

+0

はい、あなたは標準を守っていない、彼らは単純な文字列のテキストです –

+0

ありがとうございます。答えを確認してください。 – Rao

答えて

1

は、それは、行と列の形でデータを有する#%#によって分離し、レコードがキャリッジリターン改行マーカーにより分離されていることに気づきました。

ご提供いただいたデータにはフィールド数が少ない特別なレコードがありますので、動作中のスクリプトを提供するには、不要な余分なフィールドをその最後で削除する必要があります。 https://groovyconsole.appspot.com/script/5076918839803904

スクリプト =>実行コンソールに
クリックしてリンク=>編集:あなたはすぐにも、以下の手順を使用して出力を確認することができ

def str = '''Account Id#%#Territory#%#District#%#Area#%#Region#%#objname#%#~ID~#%#~Lat-Lon Linked~#%#~Latitude~#%#~Longitude~#%#~Lat-Lon Zip~#%#School Name#%#Address#%#City#%#State#%#ZIP#%#ZIP4#%#School Type#%#Status#%#School Level#%#Count Free Lunch#%#Count Reduced Lunch#%#Total Lunch Pgm#%#Total Students#%#PreKindergarten#%#Kindergarten#%#Grade 1#%#Grade 2#%#Grade 3#%#Grade 4#%#Grade 5#%#Grade 6#%#Grade 7#%#Grade 8#%#Grade 9#%#Grade 10#%#Grade 11#%#Grade 12#%#Territory1#%#Region1#%#lat#%#lon#%#terrid\r\n15709#%#Hartford, CT#%#New England#%#Unassigned#%#Unassigned#%#Account#%#15709#%#True#%#41.934711#%#-72.770021#%#06026#%#R. DUDLEY SEYMOUR SCHOOL#%#185 HARTFORD AVENUE#%#EAST GRANBY#%#CT#%#6026#%#9520#%#1#%#1#%#2#%#0#%#0#%#0#%#131#%#0#%#0#%#0#%#0#%#0#%#60#%#71#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#Hartford, CT#%#New England#%#5151204.33051376#%#-8100721.57141633#%#3\r\n15707#%#Hartford, CT#%#New England#%#Unassigned#%#Unassigned#%#Account#%#15707#%#True#%#41.934894#%#-72.730656#%#06026#%#EAST GRANBY HIGH SCHOOL#%#95 SOUTH MAIN STREET#%#EAST GRANBY#%#CT#%#6026#%#9550#%#1#%#1#%#3#%#0#%#0#%#0#%#219#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#57#%#55#%#53#%#54#%#Hartford, CT#%#New England#%#5151231.26605957#%#-8096340.03625871#%#3\r\n15708#%#Hartford, CT#%#New England#%#Unassigned#%#Unassigned#%#Account#%#15708#%#True#%#41.934894#%#-72.730656#%#06026#%#EAST GRANBY MIDDLE SCHOOL#%#95 SOUTH MAIN STREET#%#EAST GRANBY#%#CT#%#6026#%#9550#%#1#%#1#%#2#%#0#%#0#%#0#%#201#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#67#%#73#%#61#%#0#%#0#%#0#%#0#%#Hartford, CT#%#New England#%#5151231.26605957#%#-8096340.03625871#%#3\r\n15706#%#Hartford, CT#%#New England#%#Unassigned#%#Unassigned#%#Account#%#15706#%#True#%#41.944215#%#-72.732696#%#06026#%#ALLGROVE SCHOOL#%#33 TURKEY HILLS ROAD#%#EAST GRANBY#%#CT#%#6026#%#9570#%#1#%#1#%#1#%#0#%#0#%#0#%#275#%#3#%#69#%#65#%#82#%#56#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#Hartford, CT#%#New England#%#5152627.52929053#%#-8096567.12801993#%#3\r\n15710#%#Hartford, CT#%#New England#%#Unassigned#%#Unassigned#%#Account#%#15710#%#True#%#41.944215#%#-72.732696#%#06026#%#HOMEBOUND#%#33 TURKEY HILL ROAD#%#EAST GRANBY#%#CT#%#6026#%#674#%#4#%#3#%#4#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#Hartford, CT#%#New England#%#5152627.52929053#%#-8096567.12801993#%#3\r\n15923#%#Hartford, CT#%#New England#%#Unassigned#%#Unassigned#%#Account#%#15923#%#True#%#42.0027#%#-72.942#%#06027#%#HOMEBOUND#%#30 SOUTH ROAD#%#EAST HARTLAND#%#CT#%#6027#%#9710#%#4#%#3#%#4#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#0#%#Hartford, CT#%#New England#%#5161383.89953631#%#-8119866.29744296#%#3\r\n15922#%#Hartford, CT#%#New England#%#Unassigned#%#Unassigned#%#Account#%#15922#%#True#%#42.0027#%#-72.942#%#06027#%#HARTLAND ELEMENTARY SCHOOL#%#30 SOUTH ROAD#%#EAST HARTLAND#%#CT#%#6027#%#9710#%#1#%#1#%#1#%#0#%#0#%#0#%#2#%#0#%#25#%#17#%#26#%#29#%#37#%#36#%#38#%#35#%#40#%#0#%#0#%#0#%#0#%#Hartford, CT#%#New England#%#5161383.89953631#%#-8119866.29744296#%#3''' 
//split by carriage return and new line 
def data = str.split('\r\n') 
//split by field to get the just column names from header row 
def headers = data[0].split('#%#') 
//Create map with just header keys, so that it can be used while storing the data 
def headerMap = [:] 
headers.each { header -> 
    headerMap[header] = '' 
} 
/** 
* Closure allows you to query the required data 
* Need to pass all the records and row (human readable starting with 1) and header key/ field name 
* so the information is displaced as well as returns matched value 
*/ 
def getData = { recordList, row, field -> 
    println "Requested data : \n Row : ${row} \n Column : ${field} \n Column Value : ${recordList[row-1].get(field)}" 
    recordList[row-1].get(field) 
} 
// This is the variable which holds all the records 
// And each record will be in the form of a map so that it can be queried easily based on the field 
def records = [] 
for (i=1;i<data.size();i++) { 
    def fieldData = data[i].split('#%#') 
    def record = headerMap.clone() 
    if (fieldData.size() == headerMap.size()) { 
     def keys = headerMap.keySet() 
     for (j=0;j<keys.size();j++) { 
      record[keys[j]] = fieldData[j] 
     } 
     println record 
     //Add the record to records 
     records << record 
    } 
} 
//Some meta data information 
println "Headers : ${headers}" 
println "No of headers : ${headers.size()}" 
println "No of rows : ${records.size()}" 
/** 
* Here is how you can query the specific data 
* and since it returns value, you can also assign it variable as well 
*/ 
getData(records, 1, 'Territory') 
getData(records, 7, 'Account Id') 
​ 

:ここ

Groovyのスクリプトです

どのように異なるデータをクエリしますか? すでにほとんどの行にコメントを適切に記述したスクリプトを提供しています。 getData()を使用して、データ形式を取得することができます。records,row number(人間が判読可能な数は1から始まる)とフィールド名を渡すだけです。

printlnを使用していますが、soapuiで使用する必要がある場合はlog.infoに置き換えることができます。

enter image description here

+0

もう一度お返事いただきありがとうございました。 –