Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This question looked very fun and I had to give it a try even though its already has an accepted answer. Plus, the accepted answer does not seem to properly work for reputations that are greater than 999 (i.e. <strong>1,000</strong> contains a <strong>comma</strong> which is being also being split). </p> <p>Being that the format of Flair is in JSON, simply splitting on it does not always work and regex against JSON is almost impossible. While there are .NET JSON libraries out there I wanted to keep the solution all within PowerShell (including V1). </p> <p>The following uses the 3.5 <a href="http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx" rel="noreferrer">JavaScriptSerializer</a> class, which requires us to load the assembly in our script.</p> <h3>Update</h3> <p>With PowerShell 2.0 it's a lot easier to create "custom objects" with hashes. </p> <pre><code>function Get-StackOverflowReputation { param ( $UserId ) $assembly = [Reflection.Assembly]::LoadWithPartialName("System.Web.Extensions") $client = New-Object System.Net.WebClient $json = $client.DownloadString("http://stackoverflow.com/users/flair/$UserId.json") $transmogrifer = New-Object System.Web.Script.Serialization.JavaScriptSerializer $jsonFlair = $transmogrifer.DeserializeObject( $json ) $flair = New-Object PSObject -Property @{ user = $jsonFlair["displayName"]; rep = $jsonFlair["reputation"] } $flair } 1&gt; Get-StackOverflowReputation -UserId 45571 user rep ---- --- Andy Schneider 779 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload