ParseGrammar2 Function
Parses a string of name-value pairs and returns them as properties of a JavaScript object.

Syntax
var oValues = ParseGrammar2(sDelimitedString);

Parameters
sDelimitedString Required. A delimited string in the format "name1=value1^name2=value2^name3=value3^name_n=value_n". An equal sign ("=") separates each name and its value. A caret ("^") separates each name/value pair.

Return Value

Remarks
The Tellme Studio Grammar Library includes several grammars that return more than one value in a single result: CREDIT_CARD_EXPIRATION_DATE, HOUR, TIME, US_MONEY, and US_BIG_MONEY. For example, the US_MONEY grammar returns a "dollars" value as well as a "cents" value. Since multiple values are returned inside a single string (using a pre-defined text encoding), the string needs to be parsed to extract the individual return values. Use the ParseGrammar2 Javascript function to parse the return value from these grammars.
Rather than using this primitive mechanism for obtaining grammar results, consider using Mixed Initiative instead.
Examples

The following snippet provides the source to the ParseGrammar2 function. Include the source code in your application, or create a text file on your Web server and reference it in using the src attribute of the script element.

//
// Tellme Studio Toolbox - ParseGrammar Javascript function
// Copyright (C) 2001 Tellme Networks, Inc. All Rights Reserved.
//
// THIS CODE IS MADE AVAILABLE SOLELY ON AN "AS IS" BASIS, WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
// WARRANTIES THAT THE CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A
// PARTICULAR PURPOSE OR NON-INFRINGING.

function ParseGrammar2(sGramResult)
{
  var arrNames = [];
  var arrValues = [];
 
  var arrNamesValues = sGramResult.split('^');

  for (var i = 0; i < arrNamesValues.length; i++)
  {
    var arrNameValuePair = arrNamesValues[i].split('=');
    arrNames[i] = arrNameValuePair[0];
    arrValues[i] = arrNameValuePair[1];
  }

  // Special Case: US_MONEY, US_BIG_MONEY
  if (arrNames[0] == "dollars" && arrNames[1] == "cents")
  {
    if (arrValues[1] == "xx")
    {
      // arrValues[0] is the dollars, arrValues[1] is the cents
      arrValues[1] = arrValues[0];
      arrValues[0] = Math.floor(arrValues[0]/100);
      arrValues[1] = Math.floor(arrValues[1]%100);
    }

	return {'dollars' : arrValues[0], 'cents' : arrValues[1]};
  }

  // Special Case: TIME
  else if (arrNames[0] == "hour" &&
      arrNames[1] == "minute" &&
      arrNames[2] == "am_pm")
  {
    if (arrValues[1] == "xx")
    {
      // arrValues[0] is the hours, arrValues[1] is the minutes
      arrValues[1] = arrValues[0];
      arrValues[0] = Math.floor(arrValues[0]/100);
      arrValues[1] = Math.floor(arrValues[1]%100);
    }

	return {'hour' : arrValues[0], 'minute' : arrValues[1], 'am_pm' : arrValues[2]};
  }

  // if this grammar is not a special case
  else
  {
    // create an associative array (aka js object) to hold names/values
    var h = {};
    for (var j = 0; j < arrNames.length; j++)
    {
	  h[arrNames[j]] = arrValues[j];
    }
    return h;
  }
}

The following example uses the ParseGrammar2 function to parse the return value from the US_MONEY grammar. and reads the dollars and cents values back to the user.

<vxml version="2.0">

<script src="parsegrammar2.js"/>

<form id="Main">
  <block>
    <audio>This is a demo auction</audio>
  </block>

  <field name="priceamt" >
  <grammar>US_MONEY</grammar>

  <prompt>
    <audio>What's your bid? Say a dollar amount.</audio>
  </prompt>

  <catch event="noinput nomatch">
    <audio>sorry. i didn't get that. please say a dollar amount.</audio>
    <reprompt/>
  </catch>

  <filled>
     <var name="oMoney" expr="ParseGrammar2(priceamt)"/>>
      <log>dollars: <value expr="oMoney.dollars"/></log>
      <log>cents: <value expr="oMoney.cents"/></log>
      <audio>I heard you say</audio>
      <audio><value expr="oMoney.dollars"/> dollars and 
      <value expr="oMoney.cents"/> cents
      </audio>
  </filled>
  </field>
</form>

</vxml>