2014-01-17 1 views
0

노드가 가변적 인 문제가있는 json이 있습니다 (URL은 노드를 정의합니다). 아래의 "강조 표시"부분을 참조하십시오. - URL을 얻으려고합니다. & 아래 강조 표시 부분에서 fulltxt 부분을 얻으려고합니다. - 올다양한 노드가있는 Java에서 JSON 구문 분석

{ 
    "responseHeader": { 
    "status": 0, 
    "QTime": 24, 
    "params": { 
     "fl": "urlFull", 
     "indent": "true", 
     "q": "hello", 
     "_": "1389977088005", 
     "hl.simple.pre": "", 
     "hl.simple.post": "", 
     "hl.fl": "fulltxt", 
     "wt": "json", 
     "hl": "true" 
    } 
    }, 
    "response": { 
    "numFound": 3178, 
    "start": 0, 
    "docs": [ 
     { 
     "urlFull": "http://www.hellodesign.com/" 
     }, 
     { 
     "urlFull": "http://kadlot.com/" 
     }, 
     { 
     "urlFull": "http://insanityprone.tumblr.com/" 
     }, 
     { 
     "urlFull": "http://www.privatevoyeur.com/PSOctober13/am23043/index.html" 
     }, 
     { 
     "urlFull": "http://www.privatevoyeur.com/PSOctober13/am23043/qvindex.html" 
     }, 
     { 
     "urlFull": "http://seoul-arts.123.st/f268-hello" 
     }, 
     { 
     "urlFull": "http://www.edugeek.net/groups/south-west-techs/178-hello/" 
     }, 
     { 
     "urlFull": "http://www.gatewaytoroleplay.com/t1271-hello" 
     }, 
     { 
     "urlFull": "http://www.4networking.biz/forum/ViewPost/1078797" 
     }, 
     { 
     "urlFull": "http://www.blackhatim.com/f18/hello-108347.html" 
     } 
    ] 
    }, 
    "highlighting": { 
    "http://www.hellodesign.com/": { 
     "fulltxt": [ 
     "Hello You need the Latest Flash Player to view this site. Click here to download Flash Click here if you know you have Flash Address 10305 Jefferson Blvd. Culver City, CA 90232 Telephone 310-839-4885", 
     " Fax 310-839-4886 Email New Business [email protected] Press Inquiries [email protected] Career Inquiries [email protected] General Inquiries [email protected]" 
     ] 
    }, 
    "http://kadlot.com/": { 
     "fulltxt": [ 
     "Hello! Hello! Sooo... I didn't have much time to give you a prezi with nice graphics, but I thought you could help me out* with the drawings at least! So I made this site you can draw on! Try it and" 
     ] 
    }, 
    "http://insanityprone.tumblr.com/": { 
     "fulltxt": [ 
     "Hello... Hello... ~ And welcome to my facilities. Yes, mine. Not Her's. Mine. If you're curious about anything, anything at all, feel free to ask me. I've been here for a while now; I've picked a few", 
     " they came into view. Well didn’t they look familiar. Vaguely so. “Hello..” he offered a thin grin, just a sliver of those white teeth, hoping to eminate a false sense of friendliness. While he did like" 
     ] 
    }, 
    "http://www.privatevoyeur.com/PSOctober13/am23043/index.html": { 
     "fulltxt": [ 
     "Hello EscapeTrail PrivateVoyeur InstantPost Archive CamFuze PrivateVoyeur Proudly Presents:    Hello Contributor Story None From ... Comments by John Legal Advisory The photos" 
     ] 
    }, 
    "http://www.privatevoyeur.com/PSOctober13/am23043/qvindex.html": { 
     "fulltxt": [ 
     "Hello EscapeTrail PrivateVoyeur InstantPost Archive CamFuze PrivateVoyeur Proudly Presents:    Hello Contributor Story None Legal Advisory The photos below are copyright protected. You" 
     ] 
    }, 
    "http://seoul-arts.123.st/f268-hello": { 
     "fulltxt": [ 
     "HELLO! ❥S-A-U :: ANNYEONG! :: HELLO! ! & ! Atsakymai Autorius Peržiūrėjo Paskutinis pranešimas !: MEET [ Pereiti prie: 1, 2, ... , 5, 6] 83 KIM JAEJOONG 365 Today at 7:27 pm PARK BOM", 
     ": Nieko Moderatorius: STARS Permissions in this forum: Jūs negalite rašyti naujų pranešimų į šį forumą Jūs negalite atsakinėti į pranešimus šiame forume ❥S-A-U :: ANNYEONG! :: HELLO! Vartotojai", 
     ", peržiūrintys šį forumą: Nieko ❥S-A-U :: ANNYEONG! :: HELLO! Pereiti į: Pasirinkite forumą||--ANNYEONG!| |--HELLO!| |--TAISYKLĖS| |--INFORMACINĖ DĖŽUTĖ| |--NAUJOKO MENIU!| |--Švieslentė| |--Būkim" 
     ] 
    }, 
    "http://www.edugeek.net/groups/south-west-techs/178-hello/": { 
     "fulltxt": [ 
     "Hello Full Theme Forum Today's Posts Search Hello jimmy_2k 19th June 2010 10:59 AM Though i'd say hi, i'm from a school in Bristol SW-ICT 18th November 2011 10:21 AM Same!! Started off in Plymouth" 
     ] 
    }, 
    "http://www.gatewaytoroleplay.com/t1271-hello": { 
     "fulltxt": [ 
     "Hello !! Gateway to Role-Play A friendly community with various genres and freedom in role-play! Member of the Month & Year: MethosArchaic Hey! Listen! If GtR has 100,000 overall posts on the board", 
     " by the end of this year, Leah7 will dye her hair to popular vote, HikariKuragari will dye her hair red, and Venom will dye his hair the color of popular vote on the forum! Hello !! Gateway to Role-Play", 
     " :: Earth Realm :: Introductions Page 1 of 2 • Share • Page 1 of 2 • 1, 2  Hello !! by Ange Tuteur on Mon Nov 11, 2013 3:56 am Hello I'm Ange Tuteur! I'll be honest I've never ever ever role played! So" 
     ] 
    }, 
    "http://www.4networking.biz/forum/ViewPost/1078797": { 
     "fulltxt": [ 
     "Hello\n Remember Me | Password reminder | New Member? Login Member login Shiny new version of #4N Meeting Finder App out now for Apple and Android http://t.co/4KDSZdwZH5 Home What's 4Networking", 
     " forum Today's posts Last 24 hours Search forum Articles Meet the 4N Team FREE networking Home > Forum > SAY HELLO! > Hello Hello Matt Reeds Frost Group Limited 0 Member Since: 11th Nov 2013 Telephone", 
     ": Today at 04:18 Quote Hello, I am also new is 4networking to find some new frined. View Profile Send Message Leave Testimonial Find Posts Kat Evans Server Start Ltd 0 Member Since: 11th Nov 2013" 
     ] 
    }, 
    "http://www.blackhatim.com/f18/hello-108347.html": { 
     "fulltxt": [ 
     "Hello Register Help Remember Me? Forum Today's Posts FAQ Calendar Community Member List Forum Actions Mark Forums Read Quick Links View Forum Leaders What's New? Advanced Search Forum Blackhatim.com", 
     " Off Topic Hello + Reply to Thread Results 1 to 2 of 2 Thread: Hello LinkBack LinkBack URL About LinkBacks Bookmark & Share Digg this Thread! Add Thread to del.icio.us Bookmark in Technorati Tweet this", 
     " #1 greersca Junior Member Join Date Jan 2012 Posts 15 Thanks 0 Thanked 0 Times in 0 Posts Hello Just want to say hello to everyone. I am new here, and just wanted to drop a message. If anyone knows how" 
     ] 
    } 
    }, 
    "spellcheck": { 
    "suggestions": [] 
    } 
} 

예 내가 GSON & 잭슨을 사용 (실패까지, 도와주세요)하지만, 어떻게 든 값이 해달라고 ... 난 빈 위해 만든 GSON 클래스입니다 -

public class SolrResultItem { 
    public Response response; 
} 

class Response { 
    public int numFound; 
    public int start; 
    public List<Doc> docs; 
    public List<Highlighting> highlightingDocs; 
} 

class Doc { 
    public String urlFull; 
    public String title; 
    public String fulltxt; 
    public String relatedItems; 
} 
class Highlighting { 
    public String urlFull; 
    public String title; 
    //public List<String> title; 
    public List<String> fulltxt; 
} 
+0

http://json.org/의 맨 아래에있는 JSON 파서 라이브러리를 사용하고 있습니까? – philipvr

+0

예 gson & jackson을 사용했지만 어떻게 든 값을 가져 오지 못합니다 ... bean을 위해 만든 gson 클래스가 있습니다 - 위의 게시물에 추가되었습니다. – TheGeekBETA

+0

사실상 모든 JSON 구문 분석기는 기본적으로 JSON을 구조체에 매핑합니다 지도 및 목록. 일단 구조를 탐색하면 원하는 것을 찾을 수있는 간단한 문제입니다. 모든 것에 대해 클래스를 정의 할 필요는 없습니다. –

답변

0

jackson을 사용하면 "하이라이트 팅은 "

편집지도 속성을 : 여기에 잭슨 함께 사용하는 내가 수업을 할 것 수정입니다 코드를 참조하는 데 :

public class SolrResultItem { 
    public ResponseHeader responseHeader; 
    public Response response; 
    public Map<String,Fulltxt> highlighting; 
    public Spellcheck spellcheck; 
} 

class ResponseHeader{ 
    public int status; 
    public int QTime;//notation discouraged 
    public Map<String,String> params; 
} 

class Response { 
    public int numFound; 
    public int start; 
    public List<Doc> docs; 
    public List<Highlighting> highlightingDocs; 
} 

class Doc { 
    public String urlFull; 
} 
class Fulltxt{ 
    public List<String> fulltxt; 
} 

은 그냥 확실하게, 여기에 예입니다 이 코드는 매우 깨끗 아니라고 잭슨

String s=yourjson; 
Type type=SolrResultItem.class; 
ObjectMapper objectMapper = new ObjectMapper(); 
JavaType javaType = objectMapper.getTypeFactory().constructType(type); 
objectMapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true); 
SolrResultItem result = objectMapper.readValue(s, javaType); 

주를 사용하여, 우리는 upprecase 속성에 대한 개인 속성, 게터/세터, 중앙 잭슨 주석을 사용해야합니다. 이것이 도움이되기를 바랍니다. "Map String, Fulltxt"에 약간의 문제가있을 수 있습니다. jackson objectMapper가 올바르게 사용해야합니다.

+0

샘플 코드를 참조 할 수 있습니까? 나는 이것을 할 수 없었기 때문에? – TheGeekBETA