golang将复杂的字符串解析为json

I am trying to parse a string response from a server to JSON format. I am new to golang and need some help in understanding the right way to achieve a solution. Here is the response I am getting from the server -

Test 1: local 1.1.1.1  remote 2.2.2.2  state GOOD
Test ID: 2.2.2.2
Test Type: ABD
Admin State: START
DFD: Disabled
Address family: ipv4-unicast  
Options: < Refresh >  
Updates Received: 0,  Updates Sent: 7
Data Received: 853,  Data Sent: 860
Time since last received update: n/a
Number of transitions to GOOD: 1
Time since last entering GOOD state: 22384 seconds
Retry Interval: 120 seconds
Hold Time: 90 seconds,  Keep Test Time: 30 seconds

Test 2: local 1.1.1.1  remote 2.2.2.2  state GOOD
Test ID: 2.2.2.2
Test Type: ABD
Admin State: START
DFD: Disabled
Address family: ipv4-unicast  
Options: < Refresh >  
Updates Received: 0,  Updates Sent: 7
Data Received: 853,  Data Sent: 860
Time since last received update: n/a
Number of transitions to GOOD: 1
Time since last entering GOOD state: 22384 seconds
Retry Interval: 120 seconds
Hold Time: 90 seconds,  Keep Test Time: 30 seconds

Test 3: local 1.1.1.1  remote 2.2.2.2  state GOOD
Test ID: 2.2.2.2
Test Type: ABD
Admin State: START
DFD: Disabled
Address family: ipv4-unicast  
Options: < Refresh >  
Updates Received: 0,  Updates Sent: 7
Data Received: 853,  Data Sent: 860
Time since last received update: n/a
Number of transitions to GOOD: 1
Time since last entering GOOD state: 22384 seconds
Retry Interval: 120 seconds
Hold Time: 90 seconds,  Keep Test Time: 30 seconds

Thanks.

You are going to have to write a custom parser that will cut that input up into a way you can retrieve your keys and values. The strings package should be very helpful, specifically strings.Split.

I wrote a basic example that works on at least one section of your input. You are going to want to tweak it to work for your entire input. As it stands, mine will overwrite keys when continuing to read. You will want to add some sort of array structure to handle using the same keys. Also, mine uses all values as strings. I'm not sure if that is useful to you.

http://play.golang.org/p/FZ_cQ-b-bx

However, if you control the server and application that you are getting this output from, the preferred solution would be to have that application convert it to JSON.

NOTE: The code above is very brittle.