带有类型映射的数组

时间:2014-06-23 08:52:06

标签: map interface go

所以这是数组

parts:[map[content:Phillip,

This section pertains to terminated employees who are paid out in the year following the termination event.  The way the tax law works, the tax basis for your share distribution will be based on the closing stock price the day preceding notification to the transfer agent.  As such, we will distribute net shares calculating the proper withholding at fair market value the day prior to notifying the transfer agent.  We will be distributing the shares reflected on your 9/30/01 statement (6,606 shares plus cash for fractional shares).  If you would prefer to settle the taxes with a personal check, we can distribute gross shares.  Please let me know you preference.

As you know, we are in the process of transferring recordkeeping services from NTRC to Hewitt.  As such, we have a CPA, Larry Lewis, working with us to audit and set up transition files.  He has become our department expert on the PSA account (much more knowledgeable than myself)  and the various plan provision amendments.  If you would like, we can set up a conference call with you, myself, and Larry to go over the payment methodology.  Please let me know a date and time that is convenient for you.

Thanks,

Renee

 -----Original Message-----
From:   Allen, Phillip K.
Sent:   Thursday, November 01, 2001 8:26 AM
To: Ratcliff, Renee
Subject:

Renee,

Thank you for digging in to the issue of Deferred Phantom Stock Units.  It is clear that the payment will be made in shares.  However, I still don't understand which date will be used to determine the value and calculate how many shares.  The plan document under VII.  Amount of Benefit Payments reads "The value of the shares, and resulting payment amount will be based on the closing price of Enron Corp. common stock on the January 1 before the date of payment, and such payment shall be made in shares of Enron Corp. common stock."  Can you help me interpret this statement and work through the numbers on my account.

Thank you,

 Phillip Allen

 contentType:text/plain]]

我遇到的问题是尝试“内容”我尝试过像

这样的事情
t := v["parts"][0].(map[string]interface{})

这并没有像让我进一步深入兔子洞的其他一些事情那样有效。

部件位于另一个地图字符串界面内。

这是我不断得到的错误

panic: interface conversion: interface is []interface {}, not map[string]interface {}

这是我正在解析的JSON对象。

{
    "X-cc": "", 
    "From": "renee.ratcliff@enron.com", 
    "X-Folder": "\\PALLEN (Non-   Privileged)\\Allen, Phillip K.\\Inbox", 
    "Content-Transfer-Encoding": "7bit", 
    "X-bcc": "", "X-Origin": "Allen-P", 
    "To": ["k..allen@enron.com"], 
    "parts": [{
      "content": "Phillip,\r\n\r\nThis section pertains to terminated employees who are paid out in the year following the termination event.  The way the tax law works, the tax basis for your share distribution will be based on the closing stock price the day preceding notification to the transfer agent.  As such, we will distribute net shares calculating the proper withholding at fair market value the day prior to notifying the transfer agent.  We will be distributing the shares reflected on your 9/30/01 statement (6,606 shares plus cash for fractional shares).  If you would prefer to settle the taxes with a personal check, we can distribute gross shares.  Please let me know you preference.\r\n\r\nAs you know, we are in the process of transferring recordkeeping services from NTRC to Hewitt.  As such, we have a CPA, Larry Lewis, working with us to audit and set up transition files.  He has become our department expert on the PSA account (much more knowledgeable than myself)  and the various plan provision amendments.  If you would like, we can set up a conference call with you, myself, and Larry to go over the payment methodology.  Please let me know a date and time that is convenient for you.\r\n\r\nThanks,\r\n\r\nRenee\r\n\r\n -----Original Message-----\r\nFrom: \tAllen, Phillip K.  \r\nSent:\tThursday, November 01, 2001 8:26 AM\r\nTo:\tRatcliff, Renee\r\nSubject:\t\r\n\r\nRenee,\r\n\r\nThank you for digging in to the issue of Deferred Phantom Stock Units.  It is clear that the payment will be made in shares.  However, I still don't understand which date will be used to determine the value and calculate how many shares.  The plan document under VII.  Amount of Benefit Payments reads \"The value of the shares, and resulting payment amount will be based on the closing price of Enron Corp. common stock on the January 1 before the date of payment, and such payment shall be made in shares of Enron Corp. common stock.\"  Can you help me interpret this statement and work through the numbers on my account.\r\n\r\nThank you,\r\n\r\nPhillip Allen\r\n\r\n", 

    "contentType": "text/plain"}], 
    "X-FileName": "PALLEN (Non-Privileged).pst", 
    "Mime-Version": "1.0", 
    "X-From": "Ratcliff, Renee </O=ENRON/OU=NA/CN=RECIPIENTS/CN=RRATCLI>", 
    "Date": {"$date": 1004725111000}, 
    "X-To": "Allen, Phillip K. </O=ENRON/OU=NA/CN=RECIPIENTS/CN=Pallen>", 
    "Message-ID": "<19495537.1075862165839.JavaMail.evans@thyme>", 
    "Content-Type": "text/plain; charset=us-ascii", "Subject": "RE:"
}

这是代码。

http://play.golang.org/p/rJPTjvoM_t

2 个答案:

答案 0 :(得分:0)

请发布您尝试过的实际例子以及您要做的事情。

数组映射和数组映射的行为与任何其他类型一样。

在您的示例中,看起来您需要map[string][]map[string]interface{},但是您map[string][]interface{}的界面内容为[]interface{}

以下是使用map / interface / array / slices的一些示例+您显示的失败。 (http://play.golang.org/p/gmH_nVPppx

package main

import "fmt"

type Content struct {
        name string
}

func main() {
        arrayOfMap := [2]map[string]Content{
                {"part1": {name: "Philip"}},
                {"part2": {name: "John"}},
        }
        fmt.Printf("%s\n", arrayOfMap[0]["part1"].name)

        mapOfArray := map[string][2]Content{
                "parts": {
                        {name: "Philip"},
                        {name: "John"},
                },
        }
        fmt.Printf("%s\n", mapOfArray["parts"][0].name)

        mapOfArrayOfMap := map[string][2]map[string]Content{
                "parts": {
                        {"subpart": Content{name: "Philips"}},
                },
        }
        fmt.Printf("%s\n", mapOfArrayOfMap["parts"][0]["subpart"].name)

        mapOfArrayOfInterface := map[string][2]interface{}{
                "parts": {
                        map[string]interface{}{"content": Content{name: "Philips"}},
                },
        }
        fmt.Printf("%s\n", mapOfArrayOfInterface["parts"][0].(map[string]interface{})["content"].(Content).name)

        mapOfArrayOfSliceInterface := map[string][2][]interface{}{
                "parts": {
                        {
                                map[string]interface{}{
                                        "content": Content{name: "Philips"},
                                },
                        },
                },
        }
        fmt.Printf("%s\n", mapOfArrayOfSliceInterface["parts"][0][0].(map[string]interface{})["content"].(Content).name)

        v := map[string][]interface{}{
                "parts": []interface{}{
                        0: []interface{}{nil},
                },
        }
        // This will fail as shown in the given example.
        fmt.Printf("%s\n", v["parts"][0].(map[string]interface{}))
}

答案 1 :(得分:0)

好的,所以在从上面的评论中拿走了很多东西之后...我想说@creack最接近的是能够获得&#34;内容&#34;的价值。从多维界面类型是下面的链接。

http://play.golang.org/p/urBQ8NxSo8